これは、私の Android アプリ Unit Converter 用です。unit、from、toの3 つのスピナーがあります。例えば。角度、度、ラジアン。
ユニットスピナーのリスナーを追加しました。ユニットを選択すると、fromスピナーとtoスピナーが入力されます。ユーザーは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
これは、複数のユニットでは非常に長くなりました。では、別のロジックを提案できますか?