【发布时间】:2013-08-04 01:57:02
【问题描述】:
这是为我的 android 应用 Unit Converter 准备的。我有三个微调器:unit、from 和 to。 例如。角度、度数和弧度。
我为单位微调器添加了一个监听器。选择单位后,from 和 to 微调器将被填充。用户将在 from EditText 中输入输入,然后按下“计算”按钮,TextView 将包含答案。
我使用if else 实现了这个。
if unit_spinner is Angle
if from_spinner is Degree
if to_spinner is Radian
return input*0.0174532925 //1 degree = 0.0174532925 rad
else if to_spinner is Gradian
return input*1.111111111111111 //1 degree = 1.111111111111111 grad
...and so on, the cartesian product of all units
这对于多个单位来说变得很长。那么你能提出另一个逻辑吗?
【问题讨论】:
标签: android algorithm logic unit-conversion