Not sure how to describe this one so I'll just do my best. I have a ListView that always displays five strings whatever is selected. I've copied an example to place images at the left of each list item. However I have five separate images and I don't know how to set each respective image in the custom array adapter. The current code is as follows:
String s = values[position]; if (s.startsWith("Windows")) { imageView.setImageResource(R.drawable.image1); } else { imageView.setImageResource(R.drawable.image2); }
I want mine to do the following:
if index = 0 then setImageResource as image1; elseif index = 1 then setImageResource as image2, etc.
Can I do this?
2 Answers 2
If there are static values. Why you don't use switch statement. For example:
switch(position)
{
case 0:
imageView.setImage(R.drawable.image1);
break;
.
.
.
.
case 4:
imageView.setImage(R.drawable.image5);
break;
}
1 Comment
Another clean solution would be creating a POJO of the your array item.
class Item{
String text;
int imageId;
//respective setter getters
}
In your array adapter,the getView method, modify it accordingly
Comments
Explore related questions
See similar questions with these tags.