1

I am new to android dev. I want to add images in a ListView like this.

Any idea ?

j_freyre
  • 4,565
  • 2
  • 28
  • 45
mohammedsuhail
  • 691
  • 2
  • 11
  • 23
  • 3
    Take a look here: http://stackoverflow.com/questions/459729/how-to-display-list-of-images-in-listview-in-android – slhck Sep 02 '10 at 10:41

3 Answers3

1

In this tutorial you can see how to define a custom ListView. This should help you to implement your own solution.

0

Here's an efficient implementation of a complex list view by refactoring List Adapter code.

Primal Pappachan
  • 24,967
  • 19
  • 66
  • 83
0

Here is the code which will help u out to add image in list view

public class ItemsList extends ListActivity {

private ItemsAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.items_list);

    this.adapter = new ItemsAdapter(this, R.layout.items_list_item, ItemManager.getLoadedItems());
    setListAdapter(this.adapter);
}

private class ItemsAdapter extends ArrayAdapter<Item> {

    private Item[] items;

    public ItemsAdapter(Context context, int textViewResourceId, Item[] items) {
            super(context, textViewResourceId, items);
            this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.items_list_item, null);
            }

            Item it = items[position];
            if (it != null) {
                    ImageView iv = (ImageView) v.findViewById(R.id.list_item_image);
                    if (iv != null) {
                            iv.setImageDrawable(it.getImage());
                    }
            }

            return v;
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        this.adapter.getItem(position).click(this.getApplicationContext());
    }
}
John Conde
  • 212,985
  • 98
  • 444
  • 485
Rakesh Gondaliya
  • 1,225
  • 3
  • 25
  • 41