Reputation: 43
I'm developing an science app, and I have an EditText in wich I must enter an input numeric value, so the inputType is "number|numberSigned|numberDecimal", but the problem is when I want input a scientific notation number like "45.6E05", I can't input "E" character because of EditText's InputType.
How can to allow "E" character and only to show a numerical keyboard when the EditText is focused?
Upvotes: 1
Views: 1345
Reputation: 5162
There is no way to show the numerical keyboard with an extra letter E
on it, two ways around this are either make a button that inputs E
to your edittext or to use the android:digits
attribute like such:
android:digits="1234567890E."
Where all the characters in the brackets are the ones that you want the user to be able to input
To make do it using a button, in its onClickListener
you just need to put the following code
edittext.setText(edittext.getText().toString() + "E"
In the other hand if you want to insert the character in the position of the cursor then you should try this (taken from here)
int start =edittext.getSelectionStart();
String s = "E";
edittext.getText().insert(start, s);
Upvotes: 3