lundi 11 avril 2016

Should a listview Adaptor also be responsible for the listview "behaviour"?

I am coding an app where I have a listview containing a textview and a couple of buttons.

In the listview adapter, when I create the view for one listview item, I am also attaching the event handlers to the buttons, whose behavior strictly depend on the value of textview for that listview item.

Now my question is, although it seems the best thing to attach the event handlers to the buttons while creating the view in the adapter, is it a good idea too to have the event handlers themselves in the adapter? I know it will work, but mine is more a concern about separation of code jurisdiction. I find it a bit weird that an adapter also contains the code for when the buttons are fired. Do you think that the event handlers could find a better home in the activity containing the listview, rather that in the adapter? What's your opinion?

Aucun commentaire:

Enregistrer un commentaire