if statement - if else condition with radio button not working on button click in android -
i stuck in simple code. trying check radiobutton
checked , showing results on button
click. when click male radio button, shows results when check female radio button showing nothing or can not working , not showing error. don't know whats wrong code. please take look:
radiobutton radm,radf; radm=(radiobutton)findviewbyid(r.id.radiomale); radf=(radiobutton)findviewbyid(r.id.radiofemale); button find=(button) findviewbyid(r.id.btnfind); //where s spinner , find button find.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if(s.getselecteditem().tostring().equals("kg")){ if(radm.ischecked()){ int inches= myfoot*12+myinch; float sizeincm= inches*2.54f; mybmr= (float) (66.47f+ (13.7*myweight) +(5*sizeincm) -6.8 * myage); myrmr= (float) ((10*myweight)+(6.25*sizeincm)-(5*myage)+5); mygcal=level.getselecteditem().tostring(); intent intent = new intent(mainactivity.this, output_activity.class); bundle extras = new bundle(); extras.putfloat("bmr",mybmr); extras.putfloat("rmr",myrmr); extras.putstring("gcal",mygcal); intent.putextras(extras); startactivity(intent); } } else if(s.getselecteditem().tostring().equals("kg")){ if(radf.ischecked()) { int inches = myfoot * 12 + myinch; float sizeincm = inches * 2.54f; mybmr = (float) (655.1f + (9.6 * myweight) + (1.8 * sizeincm) - 4.7 * myage); myrmr = (float) ((10 * myweight) + (6.25 * sizeincm) - (5 * myage) + 5); mygcal = level.getselecteditem().tostring(); intent intent = new intent(mainactivity.this, output_activity.class); bundle extras = new bundle(); extras.putfloat("bmr", mybmr); extras.putfloat("rmr", myrmr); extras.putstring("gcal", mygcal); intent.putextras(extras); startactivity(intent); } } } });
here xml:
<radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/radmf" android:padding="4dp" android:orientation="vertical"> <radiobutton android:layout_width="match_parent" android:layout_height="45dp" android:text="male" android:checked="true" android:background="@drawable/customedittext" android:id="@+id/radiomale"/> <view android:layout_width="match_parent" android:layout_height="5dp"/> <radiobutton android:layout_width="match_parent" android:layout_height="45dp" android:text="female" android:background="@drawable/customedittext" android:id="@+id/radiofemale"/> </radiogroup>
i solved problem this:
if(s.getselecteditem().tostring().equals("kg") && radm.ischecked()){ int inches= myfoot*12+myinch; float sizeincm= inches*2.54f; mybmr= (float) (66.47f+ (13.7*myweight) +(5*sizeincm) -6.8 * myage); myrmr= (float) ((10*myweight)+(6.25*sizeincm)-(5*myage)+5); mygcal=level.getselecteditem().tostring(); intent intent = new intent(mainactivity.this, output_activity.class); bundle extras = new bundle(); extras.putfloat("bmr",mybmr); extras.putfloat("rmr",myrmr); extras.putstring("gcal",mygcal); intent.putextras(extras); startactivity(intent); } else if(s.getselecteditem().tostring().equals("kg") && radf.ischecked()){ int inches = myfoot * 12 + myinch; float sizeincm = inches * 2.54f; mybmr = (float) (655.1f + (9.6 * myweight) + (1.8 * sizeincm) - 4.7 * myage); myrmr = (float) ((10 * myweight) + (6.25 * sizeincm) - (5 * myage) + 5); mygcal = level.getselecteditem().tostring(); intent intent = new intent(mainactivity.this, output_activity.class); bundle extras = new bundle(); extras.putfloat("bmr", mybmr); extras.putfloat("rmr", myrmr); extras.putstring("gcal", mygcal); intent.putextras(extras); startactivity(intent); }
still thankful anders time. thanks
Comments
Post a Comment