Combine 2 Radiogroups in Android -


i have 2 radiogroups. first 4 buttons , second 3 buttons. need solution update timer in textview depending on checked in both radiogroups. in first radiogroup user chooses size , in second user chooses shape. gives 12 combinations. far have figured out how update textview field 1 radiogroup. in code below have shown 2 values first radiogroup (rg1). should change depending on chosen in radiogroup 2 (rg2)

i have found solution , updated code. hope can others.

    public class mainactivity extends activity implements radiogroup.oncheckedchangelistener {      textview timer;     radiogroup rg1;     radiogroup rg2;        @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         requestwindowfeature(window.feature_no_title);         setcontentview(r.layout.activity_main);          timer = (textview) findviewbyid(r.id.softtimer);          rg1 = (radiogroup) findviewbyid(r.id.myradiogroup1);         rg1.setoncheckedchangelistener(this);          rg2 = (radiogroup) findviewbyid(r.id.myradiogroup2);         rg2.setoncheckedchangelistener(this);       }   @override     public void oncheckedchanged(radiogroup group, int checkedid) {         radiobutton s1 = (radiobutton) findviewbyid(r.id.size_small);         radiobutton s2 = (radiobutton) findviewbyid(r.id.size_medium);         radiobutton s3 = (radiobutton) findviewbyid(r.id.size_large);         radiobutton s4 = (radiobutton) findviewbyid(r.id.size_xlarge);         radiobutton b1 = (radiobutton) findviewbyid(r.id.boil_soft);         radiobutton b2 = (radiobutton) findviewbyid(r.id.boil_medium);         radiobutton b3 = (radiobutton) findviewbyid(r.id.boil_hard);          if (s1.ischecked() && b1.ischecked()){             tid = 204000;             eggtimer.settext("00:03:24");         }         else if (s1.ischecked() && b2.ischecked()) {             tid = 255000;             eggtimer.settext("00:04:15");         }         else if (s1.ischecked() && b3.ischecked()) {             tid = 341000;             eggtimer.settext("00:05:41");         }         else if (s2.ischecked() && b1.ischecked()){             tid = 239000;             eggtimer.settext("00:03:59");         }         else if (s2.ischecked() && b2.ischecked()) {             tid = 279000;             eggtimer.settext("00:04:39");         }         else if (s2.ischecked() && b3.ischecked()) {             tid = 396000;             eggtimer.settext("00:06:36");         }         else if (s3.ischecked() && b1.ischecked()){             tid = 270000;             eggtimer.settext("00:04:30");         }         else if (s3.ischecked() && b2.ischecked()) {             tid = 325000;             eggtimer.settext("00:05:25");         }         else if (s3.ischecked() && b3.ischecked()) {             tid = 485000;             eggtimer.settext("00:08:05");         }         else if (s4.ischecked() && b1.ischecked()){             tid = 336000;             eggtimer.settext("00:05:36");         }         else if (s4.ischecked() && b2.ischecked()) {             tid = 400000;             eggtimer.settext("00:06:40");         }         else if (s4.ischecked() && b3.ischecked()) {             tid = 603000;             eggtimer.settext("00:10:03");         }          final counterclass timer = new counterclass(tid, 1000);         tv_start_egg1.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 timer.start();             }         });          tv_stop_egg1.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 timer.cancel();                 tid = 0;                 eggtimer.settext("00:00:00");              }          });     } } 

you can use checked radio button id radio group 2.

int radiobuttonid = rg2.getcheckedradiobuttonid(); 

now handle conditions accordingly.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -