How to use few drawable images in unlimited length of listview?


How to use few drawable images in unlimited length of listview?
I have 3 images in drawable and as it is difficult to store huge image files in drawable for limitless length of listview, I want to use these three images for the entire listview repeatedly or randomly. For more to be clear..
1st image for ----------> 1st data
2nd image for ----------> 2nd data
3rd image for ----------> 3rd data
1st image for ----------> 4th data
2nd image for ----------> 5th data
3rd image for ----------> 6th data
...................................................
...................................................
1st image for ----------> 100th data
...................................................
...................................................
and so on or randomly if possible.
I think I have to use loop and necessary condition to solve this problem. But do not know how to go through. Can anyone help me to solve this with necessary code implemented?
1 Answer
1
Oh I've just solved this problem :D. This is what I've done.
// saving images in int type array from drawable that I've already stored.
images[0] = R.drawable.amin1;
images[1] = R.drawable.amin2;
images[2] = R.drawable.amin3;
// now adding conditions when I click on submit button
if(index%3 == 0) { images[index] = images[0]; }
else if(index%2 == 0) { images[index] = images[1]; }
else { if(index > 2) { images[index] = images[2]; } }
That's very simple. :)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.