You need declare a variable to mark the next position of the pin. In the case of the code below, you can save the next position of your pin to ctr
.
public int[] pin = new int[4];
int ctr = 0; //add this to mark the index of your pin
public void PinEnterd(View view)
{
Button btnPressed = (Button) view; //get access to the button
int value = Integer.parseInt(btnPressed.getText().toString()); //get the value of the button
pin[ctr++] = value; //save inputted value and increment counter. next position after 0 is 1.
}
- When you inputted the first pin and the value of
ctr
is 0, the inputted pin will be save topin[0]
. - When you inputted the first pin and the value of
ctr
is 1, the inputted pin will be save topin[1]
. - When you inputted the first pin and the value of
ctr
is 2, the inputted pin will be save topin[2]
. - When you inputted the first pin and the value of
ctr
is 3, the inputted pin will be save topin[3]
.