Nir Schachter
Nir Schachter

Reputation: 155

Xamarin Android Azure Mobile service good design

I am building an Android app via Xamarin Mono for Android, I recently started using the azure mobile service . I need guidance regarding the architecture that should be designed for this functionality: 3 Fragments in my app will be using the Mobile service database, all of them using the same table Item: Fragment A - List Fragment - querying Item and populate the list with the result.

Fragment B - List Fragment - querying Item and populate the list with the result (with different ListItem layout than Fragment A list).

Fragment C - Fragment - Insert an item to Item table.

I currently have a Adapter class implementing BaseAdapter that holds the table and queries it and insert to it, and then populates the Fragment A list.

However this way I'm unable to show a different ListItem layout in fragment B as the adapter is already set to a specific layout.

I have tried to find documentation about the design standards when using azure mobile service but with no luck.

I would be glad if someone could refer me to a guide like that, or explain where should the MobileServiceClient, MobileServiceTable etc. should be held and where should the table methods InsertAsync, ToListAsync... should be called.

Thank you

Upvotes: 3

Views: 241

Answers (1)

Christopher Richmond
Christopher Richmond

Reputation: 656

Since you already have a instantiated class that I assume is populated there are a couple different ways of going about this. You could create an abstract base class adapter that contains all your code except for the GetView methods, and then create a specialized class adapter for each view that has the GetView method that applies to that view. When you fire up the fragment just pass it the list items in the constructor.

Alternatively (and I'm not sure how well or not this would work since I have never tried it) would be to keep 1 class, but set a bool to designate if it is View A or view B you want to display. You would need to have the fragment change the flag as appropriate for your particular requirements.

Upvotes: 0

Related Questions