Hi, Odessa Silverberg wrote: > That's because you defined n inside a method. > > change > for (int n = 1; n < 7; n++) > in > for (n = 1; n < 7; n++) > > and add a > private int n = 0; in your Activities Class. It needs to be declared > so that it's accessible everywhere in the class, because you create > onKey(...) (which is an inline implementation of the OnKeyListener > Interface) can't access variables declared inside a method!! Yes you can. But as the error message states, they must be declared as "final"(java-equivalent of "const"). Therefore I doubt it would help to make it a class variable. Instead you should declare a new local and final variable within the for-loop as follows: > > On Jun 10, 1:50 pm, MMC2 <[email protected]> wrote: >> EditText enter_count = (EditText)findViewById(R.id.enter_count); >> for (int n = 1; n < 7; n++) { final int constN = 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[constN]+" x "+et.getText()+" = "+ >> >> ((Double.parseDouble(et.getText().toString())) * 20)); >> >> et.setText(""); >> } >> } >> return false;}}); >> >> }
Best wishes Sebastian
signature.asc
Description: OpenPGP digital signature

