java - How to combine Radio button and alert dialog -


so i'm trying make activity has 4 options created radio button , confirm button below that, i'm trying every time choose 1 of 4 options , click on " confirm " button, alert dialog appear , ask customer " choose x2, sure? ", idea's how reach this?

what made far works first 1 " x ".

public class metallist extends appcompatactivity {    radiogroup radiogroup; radiobutton radiobuttonx; radiobutton radiobuttonx2; radiobutton radiobuttonx3; radiobutton radiobuttonx4;   textview result; button btnselect; button btnclear;     @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_metal_list);       radiogroup = (radiogroup) findviewbyid(r.id.radiogroup1);      radiobuttonx = (radiobutton) findviewbyid(r.id.radiobutton5);     radiobuttonx2 = (radiobutton) findviewbyid(r.id.radiobutton2);     radiobuttonx3 = (radiobutton) findviewbyid(r.id.radiobutton3);     radiobuttonx4 = (radiobutton) findviewbyid(r.id.x4btn);      result = (textview) findviewbyid(r.id.metallisttext);      btnselect = (button) findviewbyid(r.id.btnselectmetallist);     btnclear = (button) findviewbyid(r.id.btnclearmetallist);         radiogroup.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() {         @override         public void oncheckedchanged(radiogroup radiogroup, int i) {              if (radiobuttonx.ischecked()){                  txtresultmetallist.settext(" gold selected - press confirm continue");                 txtresultmetallist.settextcolor(color.parsecolor("#ffd700"));                   string first = " selected ";                 string next = "<font color='#ffd700'>x </font>";                 result.settext(html.fromhtml(next + first));               }               if (radiobuttonx2.ischecked()){                  string first = " selected ";                 string next = "<font color='#c0c0c0'>x2 </font>";                 result.settext(html.fromhtml(next + first));             }              if (radiobuttonx3.ischecked()){                  string first = " selected ";                 string next = "<font color='#9b7d12'>x3 </font>";                 result.settext(html.fromhtml(next + first));              }              if (radiobuttonx4.ischecked()){                  string first = " selected";                 string next = "<font color='#6e2907'>x4 </font>";                 result.settext(html.fromhtml(next + first));              }         }     });           handler handler1 = new handler();     handler1.postdelayed(new runnable() {         @override         public void run() {             result.animate().alpha(1f).setduration(1000);           }     },500);       handler handler2 = new handler();     handler2.postdelayed(new runnable() {         @override         public void run() {               radiobuttonx.animate().alpha(1f).setduration(500);             radiobuttonx2.animate().alpha(1f).setduration(1500);             radiobuttonx3.animate().alpha(1f).setduration(2500);             radiobuttonx4.animate().alpha(1f).setduration(3500);           }     },2000);      handler handler4 = new handler();     handler4.postdelayed(new runnable() {         @override         public void run() {              radiobuttonx.animate().translationx(-50f).setduration(500);             radiobuttonx2.animate().translationx(-50f).setduration(1500);             radiobuttonx3.animate().translationx(-50f).setduration(2500);             radiobuttonx4.animate().translationx(-50f).setduration(3500);             }     },2000);       handler handler3 = new handler();     handler3.postdelayed(new runnable() {         @override         public void run() {               btnselect.animate().alpha(1f).setduration(1000);             btnclear.animate().alpha(1f).setduration(1000);          }     },2000);       btnclear.setonclicklistener(new view.onclicklistener() {        @override        public void onclick(view view) {             radiogroup.clearcheck();            string next = "<font color='#ffffff'>please select desired metal</font>";            result.settext(html.fromhtml(next));          }    });      btnselect.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {              int id = radiogroup.getcheckedradiobuttonid();             btnselect= (radiobutton) findviewbyid(id);                     if (radiobuttonx.ischecked()){               alertdialog.builder builder1 = new alertdialog.builder(metallist.this);             builder1.settitle(" request insurace ");             builder1.setmessage(" selected * x * , sure? ");               builder1.setpositivebutton(" yes ", new dialoginterface.onclicklistener() {                 @override                 public void onclick(dialoginterface dialoginterface, int i) {                     toast.maketext(getapplicationcontext(), " x chosen - transferring... ", toast.length_short).show();                          handler handlernew = new handler();                     handlernew.postdelayed(new runnable() {                         @override                         public void run() {                              intent intentmove = new intent(metallist.this,loadingscreen.class);                             startactivity(intentmove);                          }                     },3000);                       }             });              builder1.setnegativebutton(" no ", new dialoginterface.onclicklistener() {                 @override                 public void onclick(dialoginterface dialoginterface, int i) {                      dialoginterface.cancel();                     radiogroup.clearcheck();                   }             });                alertdialog dialog = builder1.create();             dialog.show();          }        }});         if (radiobuttonx2.ischecked()){           alertdialog.builder builder2 = new alertdialog.builder(metallist.this);         builder2.settitle(" request insurance ");         builder2.setmessage(" selected * x2 * , sure? ");           builder2.setpositivebutton(" yes ", new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                 toast.maketext(getapplicationcontext(), " x2 chosen - transferring... ", toast.length_short).show();                      handler handlernew = new handler();                 handlernew.postdelayed(new runnable() {                     @override                     public void run() {                          intent intentmove = new intent(metallist.this,loadingscreen.class);                         startactivity(intentmove);                      }                 },3000);                   }         });          builder2.setnegativebutton(" no ", new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                  dialoginterface.cancel();                 radiogroup.clearcheck();               }         });            alertdialog dialog = builder2.create();         dialog.show();      }        if (radiobuttonx3.ischecked()){           alertdialog.builder builder3 = new alertdialog.builder(metallist.this);         builder3.settitle(" request insurance ");         builder3.setmessage(" selected * x3 * , sure? ");           builder3.setpositivebutton(" yes ", new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                 toast.maketext(getapplicationcontext(), " x4 chosen - transferring... ", toast.length_short).show();                      handler handlernew = new handler();                 handlernew.postdelayed(new runnable() {                     @override                     public void run() {                          intent intentmove = new intent(metallist.this,loadingscreen.class);                         startactivity(intentmove);                      }                 },3000);                   }         });          builder3.setnegativebutton(" no ", new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                  dialoginterface.cancel();                 radiogroup.clearcheck();               }         });            alertdialog dialog = builder3.create();         dialog.show();      }           if (radiobuttonx4.ischecked()){           alertdialog.builder builder4 = new alertdialog.builder(metallist.this);         builder4.settitle(" request insurance ");         builder4.setmessage(" selected * x5 * , sure? ");           builder4.setpositivebutton(" yes ", new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                 toast.maketext(getapplicationcontext(), " x5 chosen - transferring... ", toast.length_short).show();                      handler handlernew = new handler();                 handlernew.postdelayed(new runnable() {                     @override                     public void run() {                          intent intentmove = new intent(metallist.this,loadingscreen.class);                         startactivity(intentmove);                      }                 },3000);                   }         });          builder4.setnegativebutton(" no ", new dialoginterface.onclicklistener() {             @override             public void onclick(dialoginterface dialoginterface, int i) {                  dialoginterface.cancel();                 radiogroup.clearcheck();               }         });            alertdialog dialog = builder4.create();         dialog.show();      }    }} 

layout

<button     android:layout_width="match_parent"     android:layout_height="60dp"     android:background="@drawable/brown"     android:textsize="20dp"     android:textstyle="bold"     android:text="mt" />  <relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent">  <radiogroup android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/radiogroup1">     <radiobutton     android:text="   1"     android:textcolor="#ffd700"     android:textstyle="bold"     android:layout_width="200dp"     android:layout_height="60dp"     android:layout_marginleft="170dp"     android:id="@+id/radiobutton5"     android:textsize="22dp"     android:layout_margintop="100dp"     android:background="@drawable/selectordarkgreen"     android:alpha="0"/>  <radiobutton     android:text="   2"     android:textcolor="#c0c0c0"     android:layout_width="200dp"     android:layout_height="60dp"     android:id="@+id/radiobutton2"     android:alpha="0"     android:textsize="22dp"     android:textstyle="bold"     android:layout_margintop="20dp"     android:layout_below="@+id/radiobutton5"     android:layout_marginleft="170dp"     android:background="@drawable/selectordarkgreen"/>  <radiobutton     android:text="   3"     android:layout_width="200dp"     android:layout_height="60dp"     android:id="@+id/radiobutton3"     android:layout_margintop="20dp"     android:textstyle="bold"     android:alpha="0"     android:textcolor="#9b7d12"     android:textsize="22dp"     android:layout_below="@+id/radiobutton2"     android:layout_marginleft="170dp"     android:background="@drawable/selectordarkgreen"     />   <radiobutton     android:layout_width="200dp"     android:layout_height="60dp"     android:layout_margintop="20dp"     android:textsize="22dp"     android:alpha="0"     android:id="@+id/x4btn"     android:textstyle="bold"     android:textcolor="#6e2907"     android:layout_marginleft="170dp"     android:layout_below="@+id/radiobutton3"     android:text="   4"     android:background="@drawable/selectordarkgreen" />     </radiogroup>      <textview         android:layout_width="match_parent"         android:layout_height="60dp"         android:text="please select desired metal"         android:textsize="18dp"         android:textstyle="bold"         android:textcolor="#ffffff"         android:gravity="center"         android:id="@+id/metallisttext"         android:alpha="0"/>    <linearlayout android:layout_width="match_parent" android:layout_height="70dp" android:orientation="horizontal" android:layout_alignparentbottom="true">   <button     android:layout_width="150dp"     android:layout_height="60dp"     android:background="@drawable/resultenter"     android:text="confirm"     android:layout_weight="0.6"     android:id="@+id/btnselectmetallist"     android:alpha="0"/>     <button     android:layout_width="80dp"     android:layout_height="60dp"     android:text="clear"     android:layout_weight="0.4"     android:background="@drawable/resultcancel"     android:id="@+id/btnclearmetallist"     android:alpha="0"/>    </linearlayout>    </relativelayout>   </linearlayout> 

beside code contains lot's of boilerplate, came attention if clause radiobuttonx2, radiobuttonx3 , radiobuttonx4 outside btnselect click listener.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -