Adifyr
Adifyr

Reputation: 2679

Implementing Search Button on my Keyboard

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!

Upvotes: 1

Views: 986

Answers (2)

Mr.Me
Mr.Me

Reputation: 9276

    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 .

Upvotes: 1

Steve Bergamini
Steve Bergamini

Reputation: 14600

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.

Upvotes: 0

Related Questions