1

I have an EditText in my app that brings up a keyboard when tapped. When the return key is pressed, I'd like to call a Java method. Is there any boolean or method that will allow me to perform this action? I've been looking around the documentation for something that will help me, but I'm not sure exactly how to use it.

If it is not possible, is there any way to remove or disable the return key, or change it to a "Done" key on the keyboard?

JiTHiN
  • 6,548
  • 5
  • 43
  • 69
wasimsandhu
  • 4,296
  • 9
  • 27
  • 40

1 Answers1

3

You can use imeOptions - actionDone for EditText.

XML:

<EditText 
    android:id="@+id/edt_txt"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionDone"
/>

Activity:

myEdtText.setOnEditorActionListener(new OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // TODO Auto-generated method stub
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            //Call your method here
            return true;  
        }

        return false;
    }
});

Hope it helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124