[英]Need to add the value of two spinners and populate in edit text
I am having a hard time getting a spinner to populate a value. 我很难让微调器填充值。 I have two spinners, each have multiple items to choose from.
我有两个微调器,每个微调器都有多个项目可供选择。 They need to be added together and populate in a edit text box.
它们需要一起添加并填充在编辑文本框中。
I also have a discount % edit text where the user will enter a discount. 我也有一个折扣%编辑文本,用户将在其中输入折扣。 The total of the two spinners needs to be discount by the amount entered in this box.
这两个微调器的总数需要按此框中输入的数量折让。
Could anyone help me with this. 谁能帮我这个忙。 I am currently not at my computer that I am programming with so I can not paste the code i currently have but for this example could you just use, spinner "A", spinner "B", Edit text "cost", Edit text "discount"
我目前不在正在编程的计算机上,因此无法粘贴当前拥有的代码,但对于本示例,您可以使用微调器“ A”,微调器“ B”,编辑文本“ cost”,编辑文本“折扣”
Thanks for your help. 谢谢你的帮助。
Try something along the lines of this: 尝试一些类似的方法:
int subtotal = Integer.parseInt((String) spinnerA.getSelectedItem()) * Integer.parseInt((String) spinnerB.getSelectedItem());
double discount = Double.parseDouble(discountEditText.getText().toString()) / 100;
double total = subtotal * (1.0 - discount);
(This assumes that you have ensured the discount field is a valid Double and expects an input like 10
%.) (这假设您已确保折扣字段为有效的Double,并且希望输入
10
%之类的值。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.