how wonderful that you put three buttons in the list item just like I am doing now! I too am looking for a coding style (not necessarily a solution). Anyway, I would aim at:
- Performance
- Re-usability
- Loosely coupled (yet highly cohesive)
I will delegate the click handlers to an external instance which shall be defined and wired to the adapter using:
public class MyListAdapter extends BaseAdapter {
View.OnClickListener listener = null;
public View getView(...) {
buttonA.setOnClickListener(listener);
buttonB.setOnClickListener(listener);
buttonC.setOnClickListener(listener);
}
public void setItemClickListener(View.OnClickListener listener) {
this.listener = listener;
}
}
It's the listener's job to identify which button has been click. More issues must be address, for example, passing data from MyListAdapter to the listener, and streamlining the listener code as a part of the application logics.