i created a MonoDroid application where i have a ListView populated with a custom row layout.
The custom row layout has 3 textview: lblA, lblB, lblC and an invisible imageview: img
So far so good, the listview populate itself correctly and all is working and displayed as expected.
However, i am currently facing a problem on item selection where i want the invisible imageview to become visible when an item is selected and invisible when selected again. The problem is that if i select an item and continue scrolling, the row seem to repeat itself and the visible imageview infinitly!
This is a custom visual selection i am trying to implement but it is not working as i was expecting.
Here is the code on an item selection:
private void listView_ItemClick(object sender, AdapterView.ItemClickEventArgs e){
ListView lv = (sender as ListView);
View row = lv.GetChildAt(e.Position);
var item = row.FindViewById(Resource.Id.img);
item.Visibility = (item.Visibility == ViewStates.Invisible) ? ViewStates.Visible :
ViewStates.Invisible;
}
Thanks in advance!
I figured it out, i was thinking too hard actually.
In my data List i added a ‘Selected’ boolean then modified my Adapter to toggle visibility based on this boolean.
The boolean as its value affected on item click by accessing the array directly with my_list[e.Position].
To change the visual effect of the moment i just access the view from e.View.