Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - numeric keyboard with decimal separator

I have an edittext which is created programmatically (so not in xml) and I want to launch a numeric keyboard when user presses it. The problem is that I want this keyboard also to contain the decimal separator (.).

I tried many things but nothing seems to work

final EditText input = new EditText(this);

input.setKeyListener(new DigitsKeyListener()); // this gives numeric without decimal separator input.setInputType(InputType.TYPE_CLASS_NUMBER); // this gives numeric without decimal separator input.setInputType(InputType.TYPE_CLASS_PHONE);//this gives phone keyboard with all the digits and decimal separator in the second page. It is not exactly what I want

I know that there is a way to implement custom keyboard:

http://android-developers.blogspot.com/2009/04/creating-input-method.html

http://developer.android.com/resources/samples/SoftKeyboard/index.html

but it seems quite a pain and I am first looking for a quicker alternative.

All I want is one of the following: 1. Launch numeric keyboard that contains decimal separator 2. Launch standard keyboard, but set in the numeric "page" Is something of the above possible? Thank you in advance!

like image 417
george Avatar asked Jun 09 '26 00:06

george


1 Answers

I have showed the keyboard using this code:

        // Set an EditText view to get user input
    final EditText input = new EditText(this);
    alert.setView(input);
    input.setInputType((InputType.TYPE_CLASS_NUMBER + InputType.TYPE_NUMBER_FLAG_DECIMAL));
like image 119
Wiken Avatar answered Jun 10 '26 13:06

Wiken