Custom ArrayAdapter

suggest change

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