I am trying to use OnKeyListener to change the content of an EditText depending on the entry but I am having problems doing that as it seems like it is being called twice.
Here is a shortened version of the code:
public class MyKeyListener implements View.OnKeyListener{ EditText et; public MyKeyListener(EditText editText){ this.et = editText; } public boolean onKey(View v, int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_0){ this.et.setText("0"); } else { this.et.setText("1"); } } } and in the main activity I have this:
EditText et = (EditText) findViewById(R.id.myET); MyKeyListener mkl = new MoneyKeyListener(et); et.setOnKeyListener(mkl);