Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Custom Adapter GetView multiple layouts

I have added the azure mobile service component. I use a custom adapter to querry and display the data from the mobile service database table.

SalesAdapter : BaseAdapter<Sale>

I would like to populate two different list views on different fragments with the same adapter as they are showing the same object type, but I would like each list to use a different ListItem layout.

So basically I need the Adapter's GetView method to be able to differentiate which List is asking to be populated and according to that choose the right layout to inflate.

I can't figure how to do it. Appreciate the help.


  • FZelleFZelle DEMember ✭✭✭

    You can't figure it out, you have to tell the Adapter this by for ex. setting a property.

    But just because you have the same data to display you don't have to use the same Adapter.

  • NirSchachterNirSchachter USMember

    but should I create another class that implements BaseAdapter, with the same methods and queries as SalesAdapter only to get a different ListItem layout? Or should I prefer setting a property?

  • FZelleFZelle DEMember ✭✭✭

    Neither of them.

    The Adapter shouldn't be the one getting the Data, but only to feed the ListView.

    Either create a class that is responsible for retrieving the data or just set it during initialisation.

  • NirSchachterNirSchachter USMember

    Creating a class actually makes a lot of sense :)
    Thanks for enlightening me

  • NirSchachterNirSchachter USMember

    I'm trying to find a guide that explains the right way to use the azure mobile services component,
    could you refer to one?

Sign In or Register to comment.