How to Show the Number Keyboard on an Edittext in Android

How do I show the number keyboard on an EditText in android?

You can configure an inputType for your EditText:

<EditText android:inputType="number" ... />

How to open numeric keyboard when click on EditText?

add android:inputType="number" to your edittext in your xml, it will automatically open numeric keyboard when you will click inside edittext.

How do you set the EditText keyboard to only consist of numbers on Android?

After several tries, I got it!
I'm setting the keyboard values programmatically like this:

myEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);

Or if you want you can edit the XML like so:

android: inputType = "numberPassword"

Both configs will display password bullets, so we need to create a custom ClickableSpan class:

private class NumericKeyBoardTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return source;
}
}

Finally we need to implement it on the EditText in order to display the characters typed.

myEditText.setTransformationMethod(new NumericKeyBoardTransformationMethod());

This is how my keyboard looks like now:

TextInputEditText to show numeric keyboard but also allow /

Removing android:inputType and android:digits from the xml and also adding the below to the activity's onCreate() seems to do the trick.

input.setKeyListener(DigitsKeyListener.getInstance("0123456789./"));

However it's not completely clear to me that this should or will always work - see note below from the docs on DigitsKeyListener...

As for all implementations of KeyListener, this class is only concerned with hardware keyboards. Software input methods have no obligation to trigger the methods in this class.

Source: https://developer.android.com/reference/android/text/method/DigitsKeyListener

How to show soft-keyboard when edittext is focused

To force the soft keyboard to appear, you can use

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
yourEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

And for removing the focus on EditText, sadly you need to have a dummy View to grab focus.


To close it you can use

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

This works for using it in a dialog

public void showKeyboard(){
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}

public void closeKeyboard(){
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}

Number keyboard not showing on Android app

Problem is I had the EditText inside a ListView. Which is problematic for some reason.

I fixed it by setting the ListView like this

<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusable="false" />

This helped me lead to the answer
EditText inside ListView will not stay focused

Is there a way to show the numbers first on the soft keyboard for Android?

Per my research and Bert B.'s comment, there is no way to do this cross-device compatible.



Related Topics



Leave a reply



Submit