I'm new to xamarin and I've been looking everywhere for a way to select an item in a ListView and change the color of the row to let the user know which row is selected. Here is what I got
private void FormsListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs itemClickEventArgs)
{
_cicoListView.SetItemChecked(itemClickEventArgs.Position, true);
for (var i = 0; i < _ciCos.Count; i++)
{
if (itemClickEventArgs.Position == i)
{
_selectedId = ((CicoModel)_cicoListView.Adapter.GetItem(i)).Pk;
//_formsListView.SetItemChecked(itemClickEventArgs.Position, true);
}
_cicoListView.GetChildAt(i)?.SetBackgroundColor(itemClickEventArgs.Position == i ? Color.LightGray : Color.Transparent);
}
}
This method is the click handler of the item
_cicoListView.ItemClick += FormsListViewOnItemClick;
The only problem I have is when I scroll down other items are selected too because (it's my best guess) the list view recycles the rows and the positions. Thanks in advance for the help.