设置的EditText数字编程 [英] Set EditText Digits Programmatically
本文介绍了设置的EditText数字编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我基本上是想设置一个EditText的数字值编程。到目前为止,我有:
I am essentially trying to set the digits value of an EditText programmatically. So far I have:
weightInput.setInputType(InputType.TYPE_CLASS_PHONE);
weightInput.setKeyListener(DigitsKeyListener.getInstance());
这很好,但我也希望能够有一个小数点(。)。任何想法?
Which is fine, but I also want to be able to include a decimal place (.). Any ideas?
推荐答案
试试这个:
<EditText
android:inputType="number"
android:digits="0123456789."
/>
从code:
weightInput.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
但是,它允许用户以包括几个。
见Muffinbubble对实数的答案。
But, it allows the user to include several "." See Muffinbubble's answer for real numbers.
这篇关于设置的EditText数字编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文