mercredi 4 février 2015

Android: Business logic in ListView adapter?

Imagine a simple file browser. You are reading the file system and get the data back, you want to have, like read/write/access permission or the filename. Only some of the data you will need to fill in a listview (filename and filesize). But on the other hand, you will need also information, what you can do with a clicked item (open directory or call imagebrowser). What do you think, is the best way, to handle business logic?


Way #1 Store ALL data in a data object and call a setter function on the listview adapter

Advantage of this solution is the connection between clicked item and data object. When jump into the listviews clicked listener, you can get the whole data object back and run your individual business logic.


Way #2 Store only data you will need to present the listview to the user

In contrast to Way #1, you will receive only a clicked item number (0,1,2, ...) and access with this id the data object structure (array, list), which contains all data objects. When remove a item, you have to remove it from your data structure and the listview adapter. On top of that, using web technologies like paging can be very confusing.


I realized, that the MVC pattern in android is not as clear as in many design pattern books. What do you think, is the best way (maybe one of you have a better idea)?


Aucun commentaire:

Enregistrer un commentaire