I have set input type to be numberdecimal but also want to populate the editText with a "-" programmatically. I can add the text but then I am unable to edit the text as it doesn't confirm to the number decimal format. Any idea on how I can say inputtype is numberdecimal but a "-" can be allowed?
+1
A:
I am having one solution, which may helps you:
Suppose, You want to enter 2-3 numbers with "-" sign for e.g. 203-304-405.23-232.45,
then Allow user to enter this in EditText without setting any attributes.
and then you can Separate each numbers with "split()
" function , but be sure that there should be any separator sign in between the tokens.
then
String tokens[];
strInput = edittext1.getText.toString();
tokens = strInput.split(",");
then you can work with each tokens separately as tokens[0], tokens[1], for example:
num1 = tokens[0];
num2 = tokens[1];
Hope this helps you.
Enjoy!!
PM - Paresh Mayani
2010-08-04 05:16:16
Thanks Paresh for your insights... You are talking about post processing of the text entered by the user but unfortunately I cannot allow user to enter anything in EditText other than numbers. InputType has to be fixed to decimal :(
Chandra Mohan
2010-08-04 05:47:55
@chandra ohhhhhhh
PM - Paresh Mayani
2010-08-04 05:50:35
+1
A:
You will have to write your own KeyListener. You could start by downloading the source of the NumberKeyListener and take it from there.
Martin
Martin
2010-08-04 05:45:27
Martin, is there a way I can look at the source code without downloading it from the github?
Chandra Mohan
2010-08-05 05:55:57
Well there is the web interface at http://android.git.kernel.org/ - but it does not look very helpful. If at all possible you should try to get the source.
Martin
2010-08-05 07:55:20