Hashir Ali
Hashir Ali

Reputation: 191

How can i hide/disable done button on soft keyboard android?

I am working with Amazon S3 api.

Problem: Working with TextWatcher. As soon as user enters more than 3 characters in the edittext, api is called and it shows matched results. The problem starts as soon the user hit the done/enter button on soft keyboard, the api is called again and it searches again. Can i stop this second call somehow? Thanks!

Upvotes: 2

Views: 4088

Answers (5)

Vignesh
Vignesh

Reputation: 425

You can Do like editText.setImeOptions(EditorInfo.IME_ACTION_NONE);

but it won't hide the Enter/Next

Upvotes: 0

COYG
COYG

Reputation: 1598

Add

android:maxLines="1"

to you xml and enter button should be disabled.

Upvotes: 0

Sumit Jain
Sumit Jain

Reputation: 1150

just handle done click and hide the soft keyboard

editText = (EditText) findViewById(R.id.edit_text);

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
           // hide your keyboard here
           try {
                   InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                   if (inputMethodManager != null && activity.getCurrentFocus() != null) {
             inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
                   }
           } catch (Exception e) {
             e.printStackTrace();
           }
           return true;
        }
        return false;
    }
});

Upvotes: 0

Antoine El Murr
Antoine El Murr

Reputation: 317

you can change it from xml:

<EditText
...
android:imeOptions="actionNone"/>

or from code:

editText.setImeOptions(EditorInfo.IME_ACTION_NONE);

It will remove the done button whenever user trigger the softkeybord

Upvotes: 4

Mathieu Gasciolli
Mathieu Gasciolli

Reputation: 138

Maybe you can try to override the onKeyListener method in your control, to let it detect if the key pressed is 'enter' and add the code you want your 'enter' key to do ?

edittext.setOnKeyListener(new View.OnKeyListener() {

Upvotes: 0

Related Questions