Android ListView edit

Custom ArrayAdapter

By default the ArrayAdapter class creates a view for each array item by calling toString() on each item and placing the contents in a TextView.

To create a complex view for each item (for example, if you want an ImageView for each array item), extend the ArrayAdapter class and override the getView() method to return the type of View you want for each item.

For example:

public class MyAdapter extends ArrayAdapter<YourClassData>{

    private LayoutInflater inflater;

    public MyAdapter (Context context, List<YourClassData> data){
        super(context, 0, data);
        inflater = LayoutInflater.from(context);

    public long getItemId(int position)
        //It is just an example
        YourClassData data = (YourClassData) getItem(position);
        return data.ID;

    public View getView(int position, View view, ViewGroup parent)
        ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(R.layout.custom_row_layout_design, null);
            // Do some initialization
            //Retrieve the view on the item layout and set the value.
            viewHolder = new ViewHolder(view);
         else {
             viewHolder = (ViewHolder) view.getTag();
        //Retrieve your object    
        YourClassData data = (YourClassData) getItem(position);
        return view;

    private class ViewHolder
         private final TextView txt;
         private final ImageView img;

         private ViewHolder(View view) 
             txt = (TextView) view.findViewById(;
             img = (ImageView) view.findViewById(;

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
64 Menu
110 ListView
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close