I am struggling to go through each element of an Array at each button click, I can make a counter increase or decrease at each button click but I want to use for loop or while loop to do count or to go through each element of array.
Here is my code:
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (j = 0; j < 3; j++) {
d = String.valueOf(amp[j]);
Toast.makeText(MainActivity.this, d, Toast.LENGTH_LONG).show();
}//outer
}
});
I also declared a global array variable int[] amp = {4,8,7};
The problem is the loop prints each element at button click but what I want is on first click print first element of array, and if I click button again then print second element of array and so on.