Question

I'm trying to implement a search button in place of the regular enter button on my inbuilt android keyboard. I tried doing:

resultView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
System.out.println("You searched for this!");
return true;
}
return false;
}

But the regular 'enter' button is still appearing. I do not want to use XML and i'm creating my UI completely on JAVA. What should i do? Help would be appreciated. Thanks!

Was it helpful?

Solution

    EditText view = new EditText(this);
    view.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    view.setSingleLine(true);

And you are good to go, you set SingleLine attribute to change the new line button "default behavior in multi-line editext" to search button .

OTHER TIPS

Sounds like you need to set the imeOptions programmatically. Try something like this:

editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

You might have to play around with the available options to get exactly what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top