The only thing I see to achieve this is to create my own adapter class. I use this to create file browsers with various actions based on the fact that the selected item is a file or folder.
Basically, you need to create a custom adapter that extends the ArrayAdapter (you can use a different base class if all your objects inherit from the same class). Here is an example code:
public class MyCustomAdapter extends ArrayAdapter<Object> { public MyCustomAdapter(Context context, int textViewResourceId, ArrayList<Object> objects) { super(context, textViewResourceId, objects); mList = objects; } public View getView(int position, View convertView, ViewGroup parent) { Object obj = mList.get(position); View v = convertView; LayoutInflater vi = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (obj.getClass().isAssignableFrom(MyClass1.class)){ v = vi.inflate(R.layout.myclass1_item_layout, null); setupViewClass1(obj,v); } else if (obj.getClass().isAssignableFrom(MyClass2.class)){ v = vi.inflate(R.layout.myclass2_item_layout, null); setupViewClass2(obj,v); } return v; } private void setupViewClass1 (Object obj, View v){
Then you need to add OnItemClickListener as well as OnCreateContextMenuListener to handle the click and longpress event in your list, again creating a filter for the class of your object.
source share