This is a really good question I often struggle with. Seems so unnecessary duplicating so much adapter code just for different actions. I still struggle with this questions as a design issue, so my answer is not intended to provide an answer on that. However, for the part of the question about reusing the adapter or not, what I do if I wish to reuse a list/adapter is this:
For each type of list I create a global constant value to act as an identifier for that type of list. When I create a new instance of the adapter I supply the requestId/listTypeId to the adapter:
//first i create the constants somewhere globally
TYPE_ID_A = 0;
TYPE_ID_B = 1;
TYPE_ID_C = 2
//then i feed them to my adapter and set the clickListener on my list
mList.setAdapter(new MyListAdapter(mContext, listData, TYPE_ID_A));
mList.setOnItemClickListener(this);
In my adapter I set this typeId as a member variable and further then create a public function to return this id:
public class MyListAdapter extends ArrayAdapter<JSONArray> {
private final Context mContext;
private final JSONArray mItems;
private final int mListType;
//assign the values in the constructor of the adapter
public SearchListAdapter(Context context, JSONArray items, int listType) {
super(context, R.layout.item_filter_list);
mItems = items;
mContext = context;
mListType = listType;
}
//function to return the list id
public int getListType(){
return mListType;
}
}
Finally, inside my onClick listener I call this function inside my adapter to return the listTypeId which I then compare the global constants to identify what do to further:
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
MyListAdapter adapter = (MyListAdapter) adapterView.getAdapter();
int listType = adapter.getListType(); //get the listTypeId now
//now see which list type was clicked:
switch(listType){
case(TYPE_ID_A):
//to action for list A
break;
case(TYPE_ID_B):
//to action for list B
break;
}
}
This works for me but I dont think its great. If any one has another proper design pattern please let us know!