How to create a list with various elements and actions?

I want to create a list with different types of elements. They must name different intentions or do other things (display a map, etc.). It should act as contact information. The number of elements and actions is predetermined.

conact dteails

How to achieve this effect elegantly? I do not need the exact code, but recommendations and information where to look. Any help would be appreciated :)


UPDATE:

By "this effect" I mean creating a list of different types of elements (onClickListener, layout). In the picture above, you can see that you have contact with various options: calling someone, sending via email, chatting, viewing Google maps, etc. All of these options are grouped in a list.

I am wondering if this can be done using an xml layout without defining a custom Adapter class. I also want to add some static header lines, for example. name of category.

+4
source share
1 answer

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){ // setup the content of your view (labels, images, ...) } private void setupViewClass2 (Object obj, View v){ // setup the content of your view (labels, images, ...) } private ArrayList<Object> mList; } 

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.

+3
source

All Articles