How to Sync Multiple ListViews Android - java

I am displaying data: 3 fields for each record, 3 ListViews are currently displaying the corresponding data.
I did this so that I could have columns for the data.
The problem is: When you have enough data that scrolling is neccassary, I need to sync the ListViews.
Can anyone point me in the right direction? Or is there a better solution for displaying this data in column format?
Thanks

You could try registering a scroll listener on each of the lists (http://developer.android.com/reference/android/widget/AbsListView.OnScrollListener.html)
Then update the position of the other 2 lists whenever that gets called back (either http://developer.android.com/reference/android/view/View.html#scrollTo(int, int) or http://developer.android.com/reference/android/widget/AbsListView.html#smoothScrollToPosition(int))
I wouldn't recommend this though as it will not scroll smoothly or at the same time!
As Ken mentioned in a comment a single list with a custom view would work much better - consider a LinearLayout with a weightSum of 3 and your 3 views (or sub-layouts) all having a weight of 1, to get 3 equally spaced columns.

Related

Grid of fixed number of rows and columns - android studio

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

Update ViewPager views on page scrolling

My ViewPager has 5 pages (which I try to make reusable), its custom PagerAdapter has a backing array with views, I initially add (inflate) them on startup, setting current page to middle page:
0 1 |2| 3 4
Now, on page scrolling I reuse one view from opposite end of the array populating it with new data (based on calendar dates) - I take the last view in array and move it to the beginning and vice versa depending on scroll direction. Then I populate it with new data.
Reusing views:
4 0 |1| 2 3 or
1 2 |3| 4 0 and so on ...
I move and update reusable page (here 4 or 0) in onPageSelected of ViewPager.OnPageChangeListener, which causes a short scroll animation freezing because of time-consuming routines.
That's why I decided to execute all the slow code in a separate thread and then populate subviews in the page calling View's post method. Ok, it works faster now, but a little freezing is present anyway.
The question is, how can I optimize/implement such scenario properly to achieve smooth dynamic paging?

Android - TextView in a Custom ListView loses its content while scrolling

I have came across these type of questions a lot, But none of the answers solved my problem.
I am developing a mobile shopping application model. I have a custom ListView with an ImageView, and EditText(quantity), 2 Buttons for increasing and decreasing the quantity, 3 TextViews one for item Name and other two for prices and I am dynamically loading a number of Buttons for NetWeights based on the requirement through Java code and I am implementing it using CustomAdapter(Class) extending BaseAdapter and getView().
Problem 1:
When I use the condition if(convertView==null), setTag(holder) and getTag(), the dynamically loaded Buttons are getting duplicated and gets doubled in number.
Problem 2:
While scrolling the custom ListView I am loosing my data on 2 of the TextViews while the other TextView(name) is fine because in that TextView I don't Change data on runtime. On the other two TextViews(prices) I change the data on runtime using ButtonClicks(increase and decrease) where at that time when I scroll the two TextViews, it looses its content. Actually I had this same problem with the EditText(displaying quantity), I solved it using the TextWatcher by getting the value and passing it in an array and again setting it. I used the same technique (i.e) the TextWatcher for the TextViews But that did'nt Help. I also tried removing the TextWatcher and setting the text with the array and adding TextWatcher. Still I am loosing my content in those TextViews
Any Suggestions??????
Problem 1:
While using ViewHolder (setTag(), getTag()) we will be reusing the views.
For example: Let's say we have 10 listview items and the screen can display 3 items at a time. Lets say we add 2 buttons to list item 1. First time when we load the listview we will see two buttons. Lets say now we scroll down and come back to the list item 1 again, as we are reusing the views, we already have 2 buttons and if we have the code to add buttons using getTag() then 2 more buttons will be added. I think this may be causing the issue of button duplication. To add little more information, list item 1, list item 4, list item 7 and list item 10 will all use same view, as our screen in this example can display just 3 items.
Problem 2:
One idea is to store all these text values in the arrayList.
For example, lets assume we have one textView inside each list item that can be incremented/ decremented. Set textWatcher on this textView and whenever text changes add it to the arrrayList using 'position' as the index. Inside getView method when you do getTag() try to set the textView using previously stored text (that was stored inside the arrayList)if exists.

Android - Creating a Basketball Statistics screen

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/

Changing Gridview number of columns based on position

Im currently building an application that implements a GridView. However, i need to split the GridView up. For example, at position zeta the number of columns is 3 then at position 2 3 4 the number of columns change to 1.
I have had a look around but it doesn't look like its possible. Coming from an iOS Background ive done it before in some previous iOS projects so i thought i may be able to replicate it in android.
Any suggestions would be great.
Just a idea not sure if it would work. Making the gridView an auto_fit column,
then based on position make the item cell view width properly so the gridView could either put in multiple cells or just one cell in the row.

Categories

Resources