Issue
I have an array of images like this:
int[] fruitList = new int[] {
R.drawable.apple,
R.drawable.orange,
R.drawable.bannana
};
and an ImageView. For every fruit i want to a) populate the ImageView b) wait for click to open a Dialog (Choose fruit name and do something ...) and repeat for next fruit.
I thought of a for loop but doesn't make sense. I need to wait for the click before going to the next fruit.
Any ideas ??
Solution
- Hold an index for your position along the fruitList
- Set an onClickListener on the Image View.
- Create a Dialog in the onClickListener
- Subscribe any clicks in the dialog, and in that subscription change the fruit by incrementing your index (maybe
% fruitList.size
?) - In the onClickListener launch the dialog
The key difference between app development and smaller programs is that apps are all event based. A for loop isn't suited for this kind of task.
Answered By - bkach
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.