Reputation: 4656
I've created standard Android Dialog
that has a ListView
inside of it.
I've also created Adapter for this ListView
and I am passing it.
this.MyMultiSelectListView.Adapter = MyMultiSelectListAdapter;
And all that works fine. I can see the list and everything.
But there is a image on this layout and I want to change the image when that item is clicked. So this is what I tried:
this.MyMultiSelectListView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {
var clickedItem = MyMultiSelectListAdapter.GetItem(e.Position);
if(clickedItem.Selected == false) {
clickedItem.Selected = true;
MyMultiSelectListAdapter.imgView.SetBackgroundResource(Resource.Drawable.true_image);
} else {
clickedItem.Selected = false;
MyMultiSelectListAdapter.imgView.SetBackgroundResource(Resource.Drawable.false_image);
}
};
I also tried to reload it once the image was set but that didn't seem to do anything.
anything I am missing here?
Thank you for your time.
EDIT:
The image changing issue was solved by SetBackgroundResource
to SetImageDrawable
and adding @Mây Và Bão's answer at the end of the click event.
But it doesn't completely fix my issue.
It only changes image for the LAST ITEM in the list, no matter which item I click on.
How can I make sure it does it for that one specific item?
Thank you again.
Upvotes: 0
Views: 799
Reputation: 351
Try MyMultiSelectListAdapter.notifyDataSetChanged()
it will refresh the listview
Upvotes: 1