How to display a list of images in a ListView in Android?


How do I display a list of images using the ListView? I am dowloading the images at run time. The total number of images is not fixed.

3/26/2018 1:39:09 PM

I'd start with something like this (and if there is something wrong with my code, I'd of course appreciate any comment):

public class ItemsList extends ListActivity {

private ItemsAdapter adapter;

protected void onCreate(Bundle savedInstanceState) {


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

private class ItemsAdapter extends ArrayAdapter<Item> {

    private Item[] items;

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

    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(;
            if (iv != null) {

        return v;

protected void onListItemClick(ListView l, View v, int position, long id) {

E.g. extending ArrayAdapter with own type of Items (holding information about your pictures) and overriden getView() method, that prepares view for items within list. There is also method add() on ArrayAdapter to add items to the end of the list.

R.layout.items_list is simple layout with ListView

R.layout.items_list_item is layout representing one item in list

7/24/2012 5:00:06 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow