I'm currently working on an android basketball stat tracking application.
I am using the android SDK and developing it on eclipse.
I'm to the point where we are going to need a stats screen for the game that is currently active. I need to pull stats from the game that is currently running that is outputting stats into a stat table. We are using SQLite as our database to store everything.
My problem is that I know how I can pull and count the different stats, and how to output them. But I'm thinking there is an easier way to do what I'm attempting to do.
For the stat screen activity, this is what we currently have.
Don't mind the big zero in the top left, that's just a formatting issue. Don't mind the warnings either, that's because I didn't make string values for these yet.
So every single zero is its own TextView, and if a team has 20 players, that is 180 TextViews I have to populate with different numbers.
I have thought of different ways I could format the TextView ID's so I would only have to run a different code depending on the player's # for each of the 8 stats.
But in the end, I'm still using 180 different TextViews.
Is this the only way I could do something like this?
You should use a ListView with a custom View and an Adapter, refer to this
http://developer.android.com/reference/android/widget/Adapter.html
A Listview, because you can have 2 or 40 players.
a Custom View (in XML) so you can customize the fields / imageView / others
the Adapter "fills" the Custom View and put into the ListView
http://www.piwai.info/android-adapter-good-practices/
Related
I have been working on an app that adds views programmatically to a linear layout.
The problem is if I add too many views it will go off the screen.
I would like to know how to check if a certain child has hit the end of the same view group so I could add it into another layout (a linear layout below the first one) before it "flows" and go off the screen. How might I accomplish this?
Rather than reinvent the wheel yourself, I suggest that you check out the FlexboxLayout project by Google: https://github.com/google/flexbox-layout
A FlexboxLayout will automatically give you the behavior you're describing, plus the potential for much more.
Well, there are a good number of ways you could implement this in android other than going through this hustle. What ever you are trying to do at the moment may fall under one of the following cases.
Creating views programmatically most likely means you have a dynamic data set probably from an external source.
Your dataset is limited or static but just more than the average screen can display.
if any of the above apple then you are better off using a ListView or RecyclerView (Recommended). That way your data is full displayed as a scroll-able list and you don't have to worry about some items or views not showing or going of the screen. This can range from simple string list to complex nested views.
This will be very efficient as it will automatically handle optimization and usage of memory as well as performance.
I am creating a quiz app which includes some chemical and mathematical equations. I had a previous version that used a WebView and jqmath library to display the files. That version was very inefficient and was dead slow in old android phones (2 year old ones). I scraped that thing and started the quiz page again.
I have a TabLayout and a CardView. TabLayout is used to switch between the questions and CardView is used to display the questions. But I have the database setup in such a way that if two $$ occur in a string then use jqmath to format the string.
For eg : if the json is like this "Qno":5,"Question":"If the point represented by the complex number iz is rotated about the origin through the angle $$\u03c0\/2$$ in the counter clockwise direction then the complex number representing the new position is:","Option1":"iz","Option2":"-iz","Option3":"-z","Option4":"z","Correct":"C"
then the output is
I can take care of the $$ symbol with some java functions but I have no idea how to make the expression (pi divide by 2) appear as should be. When I used jqmath my output was something like this
How to achieve this in native android using java without affecting my existing code...??
UPDATE
As suggested in the comments I used this library. But this is not working properly. Sometimes it is rendering correctly sometimes not.
For Eg: Correct Rendering
Wrong Rendering
The TextView in the top is just a normal TextView that is showing the text that is being displayed. WebView is the set of text that is displayed below that.
What is wrong? Any help is appreciated
I want to create a grid or table of fixed number of rows and columns(Ex. 6x6 grid) in a layout of Android Studio. I tried using GridLayout and GridView but it requires you to put 36 EditText(Plain text) Views in it for creating a 6x6 grid. Same is the case with TableLayout where you can only insert TableRows but cannot fix the number of columns.
Bottom line is, I want a 6x6 grid which has only a 6-letter word(one character in each cell) in the beginning and one letter is typed in every turn to make a word with the existing letters.
For this, from any cell, I should be able to read the characters in the adjacent cells. I don't think creating a GridView or TableLayout and creating 36 objects of EditTextView will be the best idea. Is there a good and efficient way to do this? I need the .xml file code and also its Java class file's code.
Why you don't think that creating a layout holding views in Android framework is good and efficient way for exposing some data in a graphical interface? This is the only reason for which View class even exists. It's a main building material of your application's GUI.
Also you don't need to create it by hand. You just need to be able to address your ViewGroup (Layout) object from your Java code where you build your Activity instance. From there you have an addView() method and you can add views in a simple loop (notice that this way you can create grids of every size, not only 6x6).
Please familiarize yourself with official Android Developers site where you can read pretty much about anything relating Android Framework. For more info about layouts click here.
Try this library it might help you.
https://github.com/InQBarna/TableFixHeaders
I have a game where I want to display a scoreboard with the previous highscores. I also want to see these scores even if I re-open the app. Is it possible to display it in a TextView? Also, how am I supposed to save the scores locally?
how am I supposed to save the scores locally?
You would use a database. There are a number of libraries to simplify it, I recommend SugarORM.
Is it possible to display it in a TextView
No. You'll almost always want something more than a single TextView. That said, what to use depends a lot on the layout you want to have.
I have a program I am writing where I have 2 tabs, when one is clicked, the recyclerview on the page updates with information X (Name, email, etc). When they click on the second tab it updates with information Y (phone, password, etc).
Is it better resource management / smarter to create 2 separate recyclerviews / adapters and change which is active? Or is it better to use 1 recyclerview with 2 adapters that adjust themselves dynamically?
My goal is to make it effective, manage resources efficiently, and also be able to change between the two very quickly.
-Pat
I would create a Fragment for each tab (could be the same class). Don't worry about the resources, recyclerviews are highly optimized.
For me its the more logical approach and it's easier to understand, especially for others if you're working in a team. Also you could change the view much easier and more dynamic in future, for example in a tablet/large screen view.
greets