Gregory Buiko
Gregory Buiko

Reputation: 115

Android ListView multiple images in one item

How can I implement the following feature: each item of a ListView may contain several Images and the number of Images may vary.

for example Example of such listView

Upvotes: 1

Views: 1997

Answers (3)

Dmitriy Puchkov
Dmitriy Puchkov

Reputation: 1601

It's simple! 1.Create your custom row layout 2.Add imageviews to your row programmatically inside adapter getView method

Upvotes: 0

Panther
Panther

Reputation: 9408

override the getView method in your custom adapter for the listview. Depending on the number of images add them dynamically.

something similar to the below code

public View getView (int position, View convertView, ViewGroup parent){
if( convertView == null ){
    convertView = inflater.inflate(R.layout.my_list_item, parent, false);
}
//images is a array of bitmap here
for(int i =0;i<images.length;i++){
   ImageView img = new ImageView(getContext());
   img.setImageBitmap(images[i]);
   convertView.add(img);
}

return convertView;
}

Upvotes: 3

Abu Saleh Musa
Abu Saleh Musa

Reputation: 111

You should use a custom adapter for that. You can search for List view custom adapter and there are tons of blog about it. Like this.

Upvotes: 1

Related Questions