Skip to main content

Soft keyboard enter key event handle


i want to do some stuff on soft keyboard enter key press. so i do code like below but it execute twice but i want that only once, so anyone know about this, if know than please give me reply for this. my code and output is like below...




Code here

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt = (EditText)findViewById(R.id.txt);

txt.setOnKeyListener(new OnKeyListener() {


@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub

{
if(keyCode == KeyEvent.KEYCODE_ENTER)
{
Log.e("test","--------- on enter");
return false;
}
}
return false;
}
});

}`



This is my out put for this


Source: Tips4allCCNA FINAL EXAM

Comments

  1. The best way possible

    if(keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN){
    System.out.println("came...");
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?