android - How to get value in second spinner and third spinner after selected first spinner and calculate -


how value in second spinner , third spinner after selected first spinner , calculate [to create simple converter]

here code, there no error in code coding not run perfectly, please me guys..

public class mainactivity extends activity{  private spinner firstspinner, secondspinner, thirdspinner; private button convert; edittext input, output; double awal, numtemp; string num, hasil;   arraylist<string> choosetype = new arraylist<string>(); arraylist<string> choosesuhu = new arraylist<string>(); arraylist<string> chooseberat = new arraylist<string>(); arraylist<string> choosepanjang = new arraylist<string>(); arraylist<string> choosedata = new arraylist<string>();   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      firstspinner = (spinner) findviewbyid(r.id.choosetype);      secondspinner = (spinner) findviewbyid(r.id.choosetype1);     input = (edittext) findviewbyid(r.id.edittext);      thirdspinner = (spinner) findviewbyid(r.id.choosetype2);     output = (edittext) findviewbyid(r.id.edittext1);      convert = (button) findviewbyid(r.id.konbut);       fillarray();      firstspinner.setadapter(new arrayadapter<string>(mainactivity.this,android.r.layout.simple_dropdown_item_1line, choosetype));     firstspinner.setonitemselectedlistener(new onitemselectedlistener() {         @override         public void onitemselected(adapterview<?> arg0, view arg1, int pos,long arg3) {             // todo auto-generated method stub             if (pos == 1) {                 secondspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, choosesuhu));                 thirdspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, choosesuhu));             }             /*else if(pos == 2){                 secondspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, chooseberat));                 thirdspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, chooseberat));             }             else if(pos == 3){                 secondspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, choosepanjang));                 thirdspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, choosepanjang));             }             else if(pos == 4){                 secondspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, choosedata));                 thirdspinner.setadapter(new arrayadapter<string>(mainactivity.this, android.r.layout.simple_dropdown_item_1line, choosedata));             }*/         }          @override         public void onnothingselected(adapterview<?> arg0) {             // todo auto-generated method stub          }     });      convert.setonclicklistener(new convert());   }   public void onclicklistener(){     secondspinner.setonitemselectedlistener(new onitemselectedlistener(){         @override         public void onitemselected(adapterview<?> arg0, view arg1,int arg2, long arg3) {             // todo auto-generated method stub             if(arg2 == 0){                 num = input.gettext().tostring();                 awal = double.parsedouble(num);             }         }          @override         public void onnothingselected(adapterview<?> arg0) {             // todo auto-generated method stub          }      });      thirdspinner.setonitemselectedlistener(new onitemselectedlistener(){         @override         public void onitemselected(adapterview<?> arg0, view arg1,int arg2, long arg3) {             // todo auto-generated method stub             numtemp = awal;             hasil = numtemp.tostring();         }          @override         public void onnothingselected(adapterview<?> arg0) {             // todo auto-generated method stub          }      }); }   private class convert implements onclicklistener {     @override     public void onclick(view v) {         // todo auto-generated method stub         output.settext(hasil);     }  }  private void fillarray() {     // todo auto-generated method stub      choosetype.add("choose");     choosetype.add("suhu");     choosetype.add("berat");     choosetype.add("panjang");     choosetype.add("data");       choosesuhu.add("celcius");     choosesuhu.add("reamur");     choosesuhu.add("fahrenheit");     choosesuhu.add("kelvin");       chooseberat.add("pon");     chooseberat.add("ton");     chooseberat.add("miligram");     chooseberat.add("gram");     chooseberat.add("kilogram");     chooseberat.add("oz");       choosepanjang.add("centimeter");     choosepanjang.add("feet");     choosepanjang.add("inche");     choosepanjang.add("kilometer");     choosepanjang.add("meter");     choosepanjang.add("mile");     choosepanjang.add("centimeter");       choosedata.add("bit");     choosedata.add("byte");     choosedata.add("kilobit");     choosedata.add("kilobyte");     choosedata.add("megabit");     choosedata.add("megabyte");     choosedata.add("gigabit");     choosedata.add("gigabyte");     choosedata.add("terabit");     choosedata.add("terabyte"); } 

}

try this

otherspinner.getselecteditem().tostring(); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -