Convert weights

This app converts between stones, pounds, ounces, kilograms, grams, cups (American cooking measure of volume). It has been uploaded to Amazon apps store. It uses radio buttons, and various rounding and formatting, as well as text (numeric) input and output.

Stringsapp/res/values/strings.xml
Screen formatapp/res/layout/activity_main.xml
Code for appapp/java/com.(the project name)/MainActivity



app/res/drawable - (pictures) - nothing in here




app/res/mipmap/ic_launcher.png/ - icon for launching app

An image called ic_launcher.png is moved into all 5 versions of ic_launcher.png. It involves overwriting what's there already.




app/res/values/strings.xml - strings

<resources> <string name="app_name">Convert weights</string> <string name="convert">Convert</string> <string name="clear">Clear</string> <string name="unit">Multiple units</string> <string name="init">" ? "</string> <string name="acc0">"Approx"</string> <string name="acc1">"Exact"</string> <string name="eq">" = "</string> <string name="quart">¼</string> <string name="half">½</string> <string name="threequart">¾</string> <string name="ozName">"oz"</string> <string name="gmName">"gm"</string> <string name="lbName">"lb"</string> <string name="kgName">"kg"</string> <string name="stName">"st"</string> <string name="flourName">"cups (flour)"</string> <string name="fatName">"(fat)"</string> <string name="sugarName">"(sugar)"</string> <string name="raspberry">"*****"</string> </resources>


app/res/layout/activity_main.xml - screen format

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <!-- Stones / Pounds / Kilo --> <EditText android:id="@+id/stVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:layout_gravity="bottom" android:onClick="doClear" android:hint="@string/init" /> <TextView android:id="@+id/stDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/stName" android:layout_alignBaseline="@id/stVal" android:layout_toRightOf="@id/stVal" android:layout_toEndOf="@id/stVal" /> <TextView android:id="@+id/eq1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/eq" android:layout_alignBaseline="@id/stDesc" android:layout_toRightOf="@id/stDesc" android:layout_toEndOf="@id/stDesc" /> <EditText android:id="@+id/lbVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:layout_gravity="bottom" android:hint="@string/init" android:layout_alignBaseline="@id/eq1" android:layout_toRightOf="@id/eq1" android:layout_toEndOf="@id/eq1" /> <TextView android:id="@+id/lbDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/lbName" android:layout_alignBaseline="@id/lbVal" android:layout_toRightOf="@id/lbVal" android:layout_toEndOf="@id/lbVal" /> <TextView android:id="@+id/eq2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/eq" android:layout_alignBaseline="@id/lbDesc" android:layout_toRightOf="@id/lbDesc" android:layout_toEndOf="@id/lbDesc" /> <EditText android:id="@+id/kgVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:layout_gravity="bottom" android:hint="@string/init" android:layout_alignBaseline="@id/eq2" android:layout_toRightOf="@id/eq2" android:layout_toEndOf="@id/eq2" /> <TextView android:id="@+id/kgDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/kgName" android:layout_alignBaseline="@id/kgVal" android:layout_toRightOf="@id/kgVal" android:layout_toEndOf="@id/kgVal" /> <TextView android:id="@+id/sp1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" android:layout_alignBaseline="@id/kgDesc" android:layout_toRightOf="@id/kgDesc" android:layout_toEndOf="@id/kgDesc" /> <Button android:id="@+id/convertButton" android:text="@string/convert" android:onClick="doCalc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@id/sp1" android:layout_toRightOf="@id/sp1" android:layout_toEndOf="@id/sp1" /> <!-- Ounces / grams --> <TextView android:id="@+id/eq3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="10dp" android:text="@string/eq" android:layout_below="@id/stVal" /> <EditText android:id="@+id/ozVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:hint="@string/init" android:layout_alignBaseline="@id/eq3" android:layout_toRightOf="@id/eq3" android:layout_toEndOf="@id/eq3" /> <TextView android:id="@+id/ozDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/ozName" android:layout_alignBaseline="@id/ozVal" android:layout_toRightOf="@id/ozVal" android:layout_toEndOf="@id/ozVal" /> <TextView android:id="@+id/eq4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/eq" android:layout_alignBaseline="@id/ozDesc" android:layout_toRightOf="@id/ozDesc" android:layout_toEndOf="@id/ozDesc" /> <EditText android:id="@+id/gmVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:hint="@string/init" android:layout_alignBaseline="@id/eq4" android:layout_toRightOf="@id/eq4" android:layout_toEndOf="@id/eq4" /> <TextView android:id="@+id/gmDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/gmName" android:layout_alignBaseline="@id/gmVal" android:layout_toRightOf="@id/gmVal" android:layout_toEndOf="@id/gmVal" /> <!-- Cups --> <TextView android:id="@+id/eq5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="10dp" android:text="@string/eq" android:layout_below="@id/eq3" /> <EditText android:id="@+id/flourVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:hint="@string/init" android:layout_alignBaseline="@id/eq5" android:layout_toRightOf="@id/eq5" android:layout_toEndOf="@id/eq5" /> <TextView android:id="@+id/flourDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/flourName" android:layout_alignBaseline="@id/flourVal" android:layout_toRightOf="@id/flourVal" android:layout_toEndOf="@id/flourVal" /> <TextView android:id="@+id/eq6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/eq" android:layout_alignBaseline="@id/flourDesc" android:layout_toRightOf="@id/flourDesc" android:layout_toEndOf="@id/flourDesc" /> <EditText android:id="@+id/fatVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:hint="@string/init" android:layout_alignBaseline="@id/eq6" android:layout_toRightOf="@id/eq6" android:layout_toEndOf="@id/eq6" /> <TextView android:id="@+id/fatDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/fatName" android:layout_alignBaseline="@id/fatVal" android:layout_toRightOf="@id/fatVal" android:layout_toEndOf="@id/fatVal" /> <TextView android:id="@+id/eq7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/eq" android:layout_alignBaseline="@id/fatDesc" android:layout_toRightOf="@id/fatDesc" android:layout_toEndOf="@id/fatDesc" /> <EditText android:id="@+id/sugarVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClear" android:hint="@string/init" android:layout_alignBaseline="@id/eq7" android:layout_toRightOf="@id/eq7" android:layout_toEndOf="@id/eq7" /> <TextView android:id="@+id/sugarDesc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/sugarName" android:layout_alignBaseline="@id/sugarVal" android:layout_toRightOf="@id/sugarVal" android:layout_toEndOf="@id/sugarVal" /> <!-- stone / pounds / ounces --> <TextView android:id="@+id/eq8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="10dp" android:text="@string/eq" android:layout_below="@id/eq5" /> <EditText android:id="@+id/st2Val" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClearSt2" android:hint="@string/init" android:layout_alignBaseline="@id/eq8" android:layout_toRightOf="@id/eq8" android:layout_toEndOf="@id/eq8" /> <TextView android:id="@+id/st2Desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/stName" android:layout_alignBaseline="@id/st2Val" android:layout_toRightOf="@id/st2Val" android:layout_toEndOf="@id/st2Val" /> <EditText android:id="@+id/lb2Val" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClearLb2" android:hint="@string/init" android:layout_alignBaseline="@id/st2Desc" android:layout_toRightOf="@id/st2Desc" android:layout_toEndOf="@id/st2Desc" /> <TextView android:id="@+id/lb2Desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/lbName" android:layout_alignBaseline="@id/lb2Val" android:layout_toRightOf="@id/lb2Val" android:layout_toEndOf="@id/lb2Val" /> <EditText android:id="@+id/oz2Val" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClearOz2" android:hint="@string/init" android:layout_alignBaseline="@id/lb2Desc" android:layout_toRightOf="@id/lb2Desc" android:layout_toEndOf="@id/lb2Desc" /> <TextView android:id="@+id/oz2Desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/ozName" android:layout_alignBaseline="@id/oz2Val" android:layout_toRightOf="@id/oz2Val" android:layout_toEndOf="@id/oz2Val" /> <!-- kilo / grams --> <TextView android:id="@+id/eq9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="20dp" android:text="@string/eq" android:layout_below="@id/eq8" /> <EditText android:id="@+id/kg2Val" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClearKg2" android:hint="@string/init" android:layout_alignBaseline="@id/eq9" android:layout_toRightOf="@id/eq9" android:layout_toEndOf="@id/eq9" /> <TextView android:id="@+id/kg2Desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/kgName" android:layout_alignBaseline="@id/kg2Val" android:layout_toRightOf="@id/kg2Val" android:layout_toEndOf="@id/kg2Val" /> <EditText android:id="@+id/gm2Val" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="numberDecimal" android:onClick="doClearGm2" android:hint="@string/init" android:layout_alignBaseline="@id/kg2Desc" android:layout_toRightOf="@id/kg2Desc" android:layout_toEndOf="@id/kg2Desc" /> <TextView android:id="@+id/gm2Desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="@string/gmName" android:layout_alignBaseline="@id/gm2Val" android:layout_toRightOf="@id/gm2Val" android:layout_toEndOf="@id/gm2Val" /> <TextView android:id="@+id/sp2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="30dp" android:paddingRight="30dp" android:layout_alignBaseline="@id/gm2Desc" android:layout_toRightOf="@id/gm2Desc" android:layout_toEndOf="@id/gm2Desc" /> <Button android:id="@+id/clearButton" android:text="@string/clear" android:onClick="doClear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@id/sp2" android:layout_toRightOf="@id/sp2" android:layout_toEndOf="@id/sp2" /> <!-- toggle between Approx and Exact --> <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/acc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@id/eq9"> <RadioButton android:id="@+id/acc0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/acc0" android:onClick="clickAcc"/> <RadioButton android:id="@+id/acc1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/acc1" android:onClick="clickAcc"/> </RadioGroup> </RelativeLayout>


app/java/com.(the project name)/MainActivity - main code for app

package com.edkins.convert; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.RadioButton; public class MainActivity extends AppCompatActivity { double stAmt = 0.0; double lbAmt = 0.0; double kgAmt = 0.0; double ozAmt = 0.0; double gmAmt = 0.0; double flourAmt = 0.0; double fatAmt = 0.0; double sugarAmt = 0.0; double oz2Amt = 0.0; double gm2Amt = 0.0; double lb2Amt = 0.0; double kg2Amt = 0.0; double st2Amt = 0.0; int accType = 0; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RadioButton acc = (RadioButton) findViewById(R.id.acc0); acc.setChecked(true); accType = 0; } // handle any input public void doCalc(View view) { EditText st = (EditText) findViewById(R.id.stVal); EditText lb = (EditText) findViewById(R.id.lbVal); EditText kg = (EditText) findViewById(R.id.kgVal); EditText oz = (EditText) findViewById(R.id.ozVal); EditText gm = (EditText) findViewById(R.id.gmVal); EditText flour = (EditText) findViewById(R.id.flourVal); EditText fat = (EditText) findViewById(R.id.fatVal); EditText sugar = (EditText) findViewById(R.id.sugarVal); EditText st2 = (EditText) findViewById(R.id.st2Val); EditText lb2 = (EditText) findViewById(R.id.lb2Val); EditText oz2 = (EditText) findViewById(R.id.oz2Val); EditText kg2 = (EditText) findViewById(R.id.kg2Val); EditText gm2 = (EditText) findViewById(R.id.gm2Val); stAmt = convNum(st.getText().toString()); lbAmt = convNum(lb.getText().toString()); kgAmt = convNum(kg.getText().toString()); ozAmt = convNum(oz.getText().toString()); gmAmt = convNum(gm.getText().toString()); flourAmt = convNum(flour.getText().toString()); fatAmt = convNum(fat.getText().toString()); sugarAmt = convNum(sugar.getText().toString()); st2Amt = convNum(st2.getText().toString()); lb2Amt = convNum(lb2.getText().toString()); oz2Amt = convNum(oz2.getText().toString()); kg2Amt = convNum(kg2.getText().toString()); gm2Amt = convNum(gm2.getText().toString()); if (stAmt > 0) { lbAmt = stAmt * 14.0; lb.setText(format(lbAmt)); kgAmt = lbAmt / 2.2; kg.setText(format(kgAmt)); smallUnits(); cups(); multipleImperial(); multipleMetric(); } else if (lbAmt > 0) { stAmt = lbAmt / 14.0; st.setText(format(stAmt)); kgAmt = lbAmt / 2.2; kg.setText(format(kgAmt)); smallUnits(); cups(); multipleImperial(); multipleMetric(); } else if (kgAmt > 0) { lbAmt = kgAmt * 2.2; lb.setText(format(lbAmt)); stAmt = lbAmt / 14.0; st.setText(format(stAmt)); smallUnits(); cups(); multipleImperial(); multipleMetric(); } else if (ozAmt > 0) { gmAmt = ozAmt * 28.35; gm.setText(format(gmAmt)); bigUnits(); cups(); multipleImperial(); multipleMetric(); } else if (gmAmt > 0) { ozAmt = gmAmt / 28.35; oz.setText(format(ozAmt)); bigUnits(); cups(); multipleImperial(); multipleMetric(); } else if (flourAmt > 0) { ozAmt = flourAmt * 4; oz.setText(format(ozAmt)); gmAmt = ozAmt * 28.35; gm.setText(format(gmAmt)); fatAmt = ozAmt / 8; fat.setText(format(fatAmt)); sugarAmt = ozAmt / 7; sugar.setText(format(sugarAmt)); bigUnits(); multipleImperial(); multipleMetric(); } else if (fatAmt > 0) { ozAmt = fatAmt * 8; oz.setText(format(ozAmt)); gmAmt = ozAmt * 28.35; gm.setText(format(gmAmt)); flourAmt = ozAmt / 4; flour.setText(format(flourAmt)); sugarAmt = ozAmt / 7; sugar.setText(format(sugarAmt)); bigUnits(); multipleImperial(); multipleMetric(); } else if (sugarAmt > 0) { ozAmt = sugarAmt * 7; oz.setText(format(ozAmt)); gmAmt = ozAmt * 28.35; gm.setText(format(gmAmt)); flourAmt = ozAmt / 4; flour.setText(format(flourAmt)); fatAmt = ozAmt / 8; fat.setText(format(fatAmt)); bigUnits(); multipleImperial(); multipleMetric(); } else if (st2Amt > 0 || lb2Amt > 0 || oz2Amt > 0) { if (st2Amt == 0) {st2.setText(String.format("%4.0f", 0.0));} if (lb2Amt == 0) {lb2.setText(String.format("%4.0f", 0.0));} if (oz2Amt == 0) {oz2.setText(String.format("%4.0f", 0.0));} ozAmt = 14 * 16 * st2Amt + 16 * lb2Amt + oz2Amt; oz.setText(format(ozAmt)); gmAmt = ozAmt * 28.35; gm.setText(format(gmAmt)); bigUnits(); cups(); multipleMetric(); } else if (kg2Amt> 0 || gm2Amt > 0) { if (kg2Amt == 0) {kg2.setText(String.format("%4.0f", 0.0));} if (gm2Amt == 0) {gm2.setText(String.format("%4.0f", 0.0));} gmAmt = 1000 * kg2Amt + gm2Amt; gm.setText(format(gmAmt)); ozAmt = gmAmt / 28.35; oz.setText(format(ozAmt)); bigUnits(); cups(); multipleImperial(); } } // trap non-numerics in input string private double convNum(String inp) { try{return Double.parseDouble(inp);} catch(Exception e){return 0;} } // format fields for output private String format(double fld) { double decimal; fld = 0.1 * Math.round(10 * fld); if (accType==0) { String fract = ""; if (fld < 10) { decimal = fld - Math.floor(fld); fld = Math.floor(fld); if (decimal > 0.875) {fld = fld + 1;} else if (decimal > 0.625) {fract = getString(R.string.threequart);} else if (decimal > 0.375) {fract = getString(R.string.half);} else if (decimal > 0.125) {fract = getString(R.string.quart);} } else if (fld >= 1000) {fld = 100 * Math.round(fld/100);} else if (fld >= 500) {fld = 50 * Math.round(fld/50);} else if (fld >= 100) {fld = 10 * Math.round(fld/10);} else if (fld >= 50) {fld = 5 * Math.round(fld/5);} else {fld = Math.round(fld);} if (fld==0 && !fract.equals("")) {return fract;} else if (fld<10000) {return String.format("%4.0f", fld) + fract;} else {return getString(R.string.raspberry);} } else { decimal = fld - Math.floor(fld); if (fld>=10000) {return getString(R.string.raspberry);} else if (fld>=100 || decimal==0) { fld = Math.round(fld); return String.format("%4.0f", fld); } else {return String.format("%4.1f", fld);} } } // calculate stones, pounds and kilo public void bigUnits() { EditText st = (EditText) findViewById(R.id.stVal); EditText lb = (EditText) findViewById(R.id.lbVal); EditText kg = (EditText) findViewById(R.id.kgVal); lbAmt = ozAmt / 16; stAmt = lbAmt / 14; kgAmt = gmAmt / 1000; st.setText(format(stAmt)); lb.setText(format(lbAmt)); kg.setText(format(kgAmt)); } // calculate ounces and grams public void smallUnits() { EditText oz = (EditText) findViewById(R.id.ozVal); EditText gm = (EditText) findViewById(R.id.gmVal); ozAmt = lbAmt * 16; gmAmt = kgAmt * 1000; oz.setText(format(ozAmt)); gm.setText(format(gmAmt)); } // calculate cups public void cups() { EditText flour = (EditText) findViewById(R.id.flourVal); EditText fat = (EditText) findViewById(R.id.fatVal); EditText sugar = (EditText) findViewById(R.id.sugarVal); flourAmt = ozAmt / 4; fatAmt = ozAmt / 8; sugarAmt = ozAmt / 7; flour.setText(format(flourAmt)); fat.setText(format(fatAmt)); sugar.setText(format(sugarAmt)); } // calculate mulitple units stone/pound/ounce public void multipleImperial() { EditText st2 = (EditText) findViewById(R.id.st2Val); EditText lb2 = (EditText) findViewById(R.id.lb2Val); EditText oz2 = (EditText) findViewById(R.id.oz2Val); oz2Amt = ozAmt % 16; lb2Amt = Math.floor(ozAmt / 16); st2Amt = Math.floor(lb2Amt / 14); lb2Amt = lb2Amt - st2Amt * 14; st2.setText(String.format("%4.0f", st2Amt)); lb2.setText(String.format("%2.0f", lb2Amt)); oz2.setText(format(oz2Amt)); } // calculate mulitple units public void multipleMetric() { EditText kg2 = (EditText) findViewById(R.id.kg2Val); EditText gm2 = (EditText) findViewById(R.id.gm2Val); gm2Amt = gmAmt % 1000; kg2Amt = Math.floor(gmAmt / 1000); kg2.setText(String.format("%3.0f", kg2Amt)); gm2.setText(format(gm2Amt)); } // clear all fields public void doClear(View view) { EditText st = (EditText) findViewById(R.id.stVal); EditText lb = (EditText) findViewById(R.id.lbVal); EditText kg = (EditText) findViewById(R.id.kgVal); EditText oz = (EditText) findViewById(R.id.ozVal); EditText gm = (EditText) findViewById(R.id.gmVal); EditText flour = (EditText) findViewById(R.id.flourVal); EditText fat = (EditText) findViewById(R.id.fatVal); EditText sugar = (EditText) findViewById(R.id.sugarVal); EditText st2 = (EditText) findViewById(R.id.st2Val); EditText lb2 = (EditText) findViewById(R.id.lb2Val); EditText oz2 = (EditText) findViewById(R.id.oz2Val); EditText kg2 = (EditText) findViewById(R.id.kg2Val); EditText gm2 = (EditText) findViewById(R.id.gm2Val); st.setText(""); lb.setText(""); kg.setText(""); oz.setText(""); gm.setText(""); flour.setText(""); fat.setText(""); sugar.setText(""); st2.setText(""); lb2.setText(""); oz2.setText(""); kg2.setText(""); gm2.setText(""); stAmt = 0.0; lbAmt = 0.0; kgAmt = 0.0; ozAmt = 0.0; gmAmt = 0.0; flourAmt = 0.0; fatAmt = 0.0; sugarAmt = 0.0; oz2Amt = 0.0; gm2Amt = 0.0; lb2Amt = 0.0; kg2Amt = 0.0; st2Amt = 0.0; } // click on st field 2 public void doClearSt2(View view) { EditText st2 = (EditText) findViewById(R.id.st2Val); st2Amt = convNum(st2.getText().toString()); if (st2Amt>0) {doClear(view);} } // click on lb field 2 public void doClearLb2(View view) { EditText lb2 = (EditText) findViewById(R.id.lb2Val); lb2Amt = convNum(lb2.getText().toString()); if (lb2Amt>0) {doClear(view);} } // click on oz field 2 public void doClearOz2(View view) { EditText oz2 = (EditText) findViewById(R.id.oz2Val); oz2Amt = convNum(oz2.getText().toString()); if (oz2Amt>0) {doClear(view);} } // click on kg field 2 public void doClearKg2(View view) { EditText kg2 = (EditText) findViewById(R.id.kg2Val); kg2Amt = convNum(kg2.getText().toString()); if (kg2Amt>0) {doClear(view);} } // click on gm field 2 public void doClearGm2(View view) { EditText gm2 = (EditText) findViewById(R.id.gm2Val); gm2Amt = convNum(gm2.getText().toString()); if (gm2Amt>0) {doClear(view);} } // change output style public void clickAcc(View view) { // Is the button now checked? boolean checked = ((RadioButton) view).isChecked(); // Check which radio button was clicked switch(view.getId()) { case R.id.acc0: if (checked) { accType = 0; break; } case R.id.acc1: if (checked) { accType = 1; break; } } redo(); } public void redo() { EditText lb = (EditText) findViewById(R.id.lbVal); EditText kg = (EditText) findViewById(R.id.kgVal); EditText st = (EditText) findViewById(R.id.stVal); EditText oz = (EditText) findViewById(R.id.ozVal); EditText gm = (EditText) findViewById(R.id.gmVal); EditText flour = (EditText) findViewById(R.id.flourVal); EditText fat = (EditText) findViewById(R.id.fatVal); EditText sugar = (EditText) findViewById(R.id.sugarVal); EditText lb2 = (EditText) findViewById(R.id.lb2Val); EditText kg2 = (EditText) findViewById(R.id.kg2Val); EditText st2 = (EditText) findViewById(R.id.st2Val); EditText oz2 = (EditText) findViewById(R.id.oz2Val); EditText gm2 = (EditText) findViewById(R.id.gm2Val); st.setText(format(stAmt)); lb.setText(format(lbAmt)); kg.setText(format(kgAmt)); oz.setText(format(ozAmt)); gm.setText(format(gmAmt)); flour.setText(format(flourAmt)); fat.setText(format(fatAmt)); sugar.setText(format(sugarAmt)); st2.setText(format(st2Amt)); lb2.setText(format(lb2Amt)); kg2.setText(format(kg2Amt)); gm2.setText(format(gm2Amt)); oz2.setText(format(oz2Amt)); } }


Index to my other websites

© Jo Edkins 2016