Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As an example, for converting mass to and from different units, I would go through an intermediate unit.</p> <p>eg. lets say I have the following</p> <pre><code>final int TYPE_KG = 0; final int TYPE_POUNDS = 1; // these two values come from your spinners int sourceUnitType; // eg 0=kg, 1=pounds, ... int destUnitType; // same types as the source unit type </code></pre> <p>Then you can convert the source number into your intermediate units, like kilograms, using a function</p> <pre><code>double convertMassToKg(int sourceUnitType, double source) { switch (sourceUnitType) { case TYPE_KG: return source; case TYPE_POUND: return source * 0.453592; } } </code></pre> <p>then convert the intermediate value into the destination units</p> <pre><code>double convertKgToMass(int destinationUnitType, double kilos) { switch (destinationUnitType) { case TYPE_KG: return kilos; case TYPE_POUND: return kilos / 0.453592; } } </code></pre> <p>That's just my take on the problem anyway. What values can your spinners take? Because it doesn't make sense to let somebody try to convert kilometers to kilograms for example, so depending upon how you have broken up your program (i.e. is this form just for converting mass?) then perhaps you can approach it a little differently.</p> <p>You could let the user select the source type in the first spinner, and then update the second spinner with only those types which make sense, eg if the first spinner is selected to "kilometers" then the second could have the options "miles", "centimeters", "yards", etc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload