[英]How to insert a money amount in Android App?
I'm building an Android app and I want the users to be able to insert an amount of money. 我正在构建一个Android应用程序,我希望用户能够插入一笔钱。 For this I want two boxes, one for the whole number of Euro's, and one for the decimals.
为此,我想要两个盒子,一个用于整个欧元,一个用于小数。 For this I can of course us two textViews and convert the contents to a BigDecimal (the type we use for money denominations).
为此,我当然可以使用两个textViews并将内容转换为BigDecimal(我们用于货币面额的类型)。 There are two downside to this though;
但这有两个缺点;
When defining the xml I can't find any specific "numberView" or something similar. 在定义xml时,我找不到任何特定的“numberView”或类似的东西。 Seeing that this occurs in more than just our app, I suppose there is a better way of doing this.
看到这不仅仅发生在我们的应用程序中,我想有更好的方法来做到这一点。 I searched around, but I can't really find what I'm looking for (although I might search for the wrong words).
我四处寻找,但我无法找到我正在寻找的东西(尽管我可能会搜索错误的单词)。
So my question; 所以我的问题; does anybody know how I should handle inserting money amounts in an Android app?
有人知道我应该如何处理在Android应用程序中插入金额?
For your first question: ardroid:inputType="numberDecimal"
对于你的第一个问题:
ardroid:inputType="numberDecimal"
For your second question: Add a click listener to the dot view (textbox, or whatever it is) to focus on the second EditText. 对于第二个问题:向点视图(文本框或其他任何内容)添加单击侦听器以专注于第二个EditText。
Edit: If the user has a non standard keyboard, it may not accept the numberDecimal input type. 编辑:如果用户具有非标准键盘,则可能不接受numberDecimal输入类型。 It may also be a good idea to set set
android:digits="0,1,2,3,4,5,6,7,8,9"
设置set
android:digits="0,1,2,3,4,5,6,7,8,9"
也可能是一个好主意
Steps : 脚步 :
1)Use android:inputType="numberDecimal" 1)使用android:inputType =“numberDecimal”
2) Then implement TextWatcher in your java class. 2)然后在java类中实现TextWatcher。
3) Inside onCreate() method set listener 3)在onCreate()方法中设置监听器
EditText e1 = (EditText) findViewById(R.id.et1); EditText e1 =(EditText)findViewById(R.id.et1); e1.addTextChangedListener(this);
e1.addTextChangedListener(本);
4) 4)
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
if (arg0.toString().contains(".")) {
// e2.requestFocus(); // Set focus to second editText
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.