Reputation: 133
I tried a few ways to bind List elements to ListView but it did not work out. I always get the error "can not convert List
List<string> numbersListString= new List<string> {
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
};
listView numbersListView = root.FindViewById<ListView>(Resource.Id.numbers);
var adapter = new ArrayAdapter<string>(Context,
Android.Resource.Layout.ActivityListItem, numbersListString);
adapter.AddAll(Android.Resource.Layout.ActivityListItem);
numbersListView.Adapter = adapter;
Upvotes: 0
Views: 580
Reputation: 18861
Cause: It seems that you used the value of params textViewResourceId as ActivityListItem
in ArrayAdapter . However , it requires the source ID to be a TextView , not a string .
Solution: You can use SimpleExpandableListItem1
instead of it.
var adapter = new ArrayAdapter<string>(context, Android.Resource.Layout.SimpleExpandableListItem1, numbersListString);
For more details about List Item Layouts
you can check https://robgibbens.com/androids-built-in-list-item-layouts/
Upvotes: 1