Android - 自定义计算器?
我正在编写一个自定义计算器 Android 应用程序。基本上,我有五个编辑文本、一个计算按钮和一个重置按钮。我已经连接了重置按钮,以便单击重置按钮时它将所有五个编辑文本的值设置为“”。
我将如何获取计算按钮单击时所有编辑文本的值并制定算法?由于有五个值,我是否需要将每个值保存到某种临时缓存字符串中?
我对此真的非常陌生,所以最好使用简单的英语。 感谢您的任何回复。
I am writing a custom calculator Android app. Basically, I have five edittexts, a calculate button and a reset button. I have hooked up the reset button so that onclick of the reset button it sets the value of all five edittexts to "".
How would I go about getting the values of all the edittexts on calculate button click and making an algorithm? Since there are five values, would I need to save each to a sort of temporary cache string?
I am really, really new to this so very plain english is preferable.
Thanks for any reply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要计算的是总和,那么您应该迭代编辑文本(您可以方便地将其保存在数组或集合中......实际上我宁愿选择数组),而且,将其添加到辅助变量中的先前值。
我不明白问题出在哪里。也许我误解了什么。查看您当前的代码可能会有所帮助。
If what you're trying to calculate is a sum, then you should iterate through the Edit Texts (which you can conveniently save in an Array or a Collection... I'd rather go for the Array actually), and, well, add it to the previous value in an auxiliary variable.
I don't get where is the problem. Maybe I'm misunderstanding something. Seeing your current code could help.