views:

970

answers:

3

I am having edittext field i am setting following property so that i display done button on the kayboard when user click on textfield.

editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

When user click done button on the screen keyboard(finish typing) i want to change radio button sate, how can i track done done button is hit from screen keyboard ?

alt text

A: 

setOnkeyListener attached with edittext fixed the problem.

Faisal khan
+1  A: 

More details on how to set the OnKeyListener, and have it listen for the Done button.

First add OnKeyListener to the implements section of your class. Then add the function defined in the OnKeyListener interface:

/*
 * Respond to soft keyboard events, look for the DONE press on the password field.
 */
public boolean onKey(View v, int keyCode, KeyEvent event)
{
    if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
        (keyCode == KeyEvent.KEYCODE_ENTER))
    {
        // Done pressed!  Do something here.
    }
    // Returning false allows other listeners to react to the press.
    return false;
}

Given an EditText object:

EditText textField = (EditText)findViewById(R.id.MyEditText);
textField.setOnKeyListener(this);
Robert Hawkey
A: 

Hey, can u tell me how u solved this problem? None of the overriden methods get called.

miku
could not track done button click, instead i used textchange listener on the editext and when ever you press any key it get fire.
Faisal khan