Reputation: 846
Using Xamarin Android with the MvvmCross framework.
I have a list of people, where each person has a nested list of Pets. The people are displayed in a ListView. The nested Pets are displayed in a nested ListView for each person.
How can I assign a custom adapter for each Pets list so the animals can be shown with the itemplate according to the type of animal?
simplified classes:
List<Person> People
class Person
{
string Name {get; set; }
bool Sex {get; set; }
List<IAnimal> Pets {get; set; }
}
class Fish: IAnimal
{
string Name {get; set; }
bool HasScales {get; set; }
}
class Bird: IAnimal
{
string Name {get;set; }
bool CanFly {get; set; }
int WingSpan {get; set; }
}
Regards,
Arthur
Upvotes: 1
Views: 1010
Reputation: 66882
Putting ListView
s within ListView
s is often a bad idea from a UX perspective - as the two will scroll independently and consume Touch operations independently. You can if you prefer:
How can I assign a custom adapter for each Pets list so the animals can be shown with the itemplate according to the type of animal?
Regardless of which approach you choose to use above, you will need to get hold of the MvxListView
or MvxLinearLayout
or whatever using FindViewById
in its parent - and then you can create and set the Adapter - see an example in https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/Working%20With%20Collections/Collections.Droid/Views/PolymorphicListItemTypesView.cs
If the Adapter parent is itself a list view, then this means you will need to provide a custom MvxListItemView
as that parent - e.g. see how a custom view is returned in MvxListView create binding for template layout from code
Upvotes: 1