I am trying to enter 7 entries using an EditText in a for loop.
But I get the error message "Cannot refer to a non final variable n
inside an inner class defined in a different method. Without the for
loop I can enter one entry. How do I set up a loop to do this.
EditText enter_count = (EditText)findViewById(R.id.enter_count);
for (int n = 1; n < 7; n++)
{enter_count.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode,
KeyEvent
event) {
if (event.getAction() ==
KeyEvent.ACTION_DOWN) {
if (keyCode ==
KeyEvent.KEYCODE_DPAD_CENTER){
TextView tv =
(TextView)findViewById(R.id.mmc);
EditText et = (EditText)findViewById
(R.id.enter_count);
tv.setText(denoms[n]+" x
"+et.getText()+" = "+
((Double.parseDouble(et.getText().toString())) * 20));
et.setText("");
}
}
return false;}});
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---