I'm not sure there are other ways to do this, but I do it this way: I installed a click listener in the activity class (and not on the adapter, which I think makes more sense). SAve an array of classes that you want to call:
Class[] classList = new Class[]{class1.class, class2.class....};
add listener to watchlist
lv.setOnItemClickListener(listviewClickListener());
Then the onItemClickListener method:
private OnItemClickListener listviewClickListener() { OnItemClickListener clickListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
I have not tested an array of class literals, but I think this should work.
Edit: I consider that you want to create different actions for each element (those who think about it do not make sense (having no context), since all elements in the list form belong to the same group, and therefore probably can be used in the same way ) Otherwise, you do not need a list of actions, and just add the one you want to the intent.
source share