ListView Selection Issue in Android -
what do i have
I have a list file device. I have a hidden image view that I want to visualize when a user clicks on the "Select All" button.
Problem
Select all buttons when the user clicks, all the items are not selected when I scroll down, I think Some items have not been selected (the view of the image is still unreliable).
My Code
Select AllSetOnClickListener (New OnClickListener) {@Override Click Public Zero (see V) {List & lt; Items & gt; Select list = dir; (Int i = 1; i & lt; list.getChildCount (); i ++) {tmpView = list.getChildAt (I) Selection = (image view) tmpView.findViewById (select RID file); Select .net disableability (see Visualic);} for (int i = 1; i & lt; selectList.size (); i ++) {item o = Adapter.getItem (i); O.setSelected ();}}});
Please suggest solving this problem? I know that list view items are reused and this problem is actually causing this problem, but I do not know how to solve this problem.
Your approach is not correct because ListView.getChildCount () returns only the list of visible list items.
I suggest this a clean way: try adding the selected item to your item, then you can update your view by notifying the dataset change. It looks like:
Public category items {Boolean selected; }
and your adapter should like it:
see public getView (see the status of the interview, seeviewview, view group guardian) {/ ( Items selected) {yourImageView.setVisibility (see Visual.); } Else {yourImageView.setVisibility (see. INVISIBLE); }}
Finally, click on all of your buttons listener:
list & lt; Items & gt; YourList = getYourListData (); (Int i = 1; i & lt; yourList.size (); i ++) {item o = yourList.get (i); O.selected = true; } // Remember dataset changed adapter.notifyDatasetChanged ();
Comments
Post a Comment