简体   繁体   English

需要添加两个微调器的值并在编辑文本中填充

[英]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. 谢谢你的帮助。

what exactly is the problem? 到底是什么问题? can you not get the selected spinner values? 您无法获得所选的微调器值吗?

pls see the spinner example here as well as the documentation here . 请参见此处的微调器示例以及此处的文档。 especially look for setOnItemSelectedListener(). 特别是寻找setOnItemSelectedListener()。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM