4

I don't want to show the virtual keyboard.

I tried the below method but it doesn't make any difference.

InputMethodManager imm =     InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(enter_count.getWindowToken(), 0);

enter_count is my edit text I have tried reading up on the InputMethod Manager but can't follow it.

I can set the input type of my edit text called enter_count as follows

enter_count.setInputType( InputType.TYPE_NULL );

but then I can't specify to only accept numeric input

Can you please give me a reasonable solution to simply not show the virtual keyboard without losing the ability to only accept numeric input on the physical keyboard.

richsage
  • 26,912
  • 8
  • 58
  • 65

4 Answers4

3

How about this?

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

editText.setKeyListener(new NumberKeyListener() {

    @Override
    public int getInputType() {
        return InputType.TYPE_NULL;
    }

    @Override
    protected char[] getAcceptedChars() {
        return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    }
});
glr
  • 2,147
  • 1
  • 14
  • 10
1

you have to use this in your AndroidManifest.xml file

So add

android:configChanges="orientation|keyboardHidden"

But with that your keyboard will always be hidden in that Activity.

Wouter

wouter88
  • 1,294
  • 4
  • 15
  • 19
1

Have you tried adding this in the Activity tag of your manifest? android:windowSoftInputMode="stateHidden"

Apk
  • 153
  • 1
  • 2
  • 18
0

Add this in yourSendData() function

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(textEntered.getWindowToken(),0); 

OR use this

InputMethodManager.RESULT_UNCHANGED_SHOWN);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

this work :)

Noaman Akram
  • 3,680
  • 4
  • 20
  • 37
Muhammad Usman Ghani
  • 1,279
  • 13
  • 19