android - How to enable and disable radiobutton inside Radiogroup items in dialog -
i have alert dialog, consist of radio-group, question how enable &disable radio button, when click on 1 radio button, should disable till, click on next radio button. please me out.
public class adddriverstatedialog extends dialogfragment { private static adddriverstatedialog adddriverstatedialog; // data references private int driver_state = 0; private calendar calendar; private int year, month, day, hours, minutes; private simpledateformat dateformat = new simpledateformat("eee, d mmm yyyy"); private simpledateformat timeformat = new simpledateformat("h:mm a"); // ui references private view view; public linearlayout editabledetails; private radiorealbuttongroup radiobuttongroup; private radiorealbutton radiobutton_offduty,radiobutton_onduty,radiobutton_sleeper,radiobutton_driving,radiobutton_yard,radiobutton_personal; private edittext note, et_date, time, odoreading, location; private checkbox insertlog, switchdriver; private spinner spinner; private mainactivity mainactivity; // picker dialogs private datepickerdialog datepickerdialog; private timepickerdialog timepickerdialog; public static adddriverstatedialog newinstance(mainactivity mainactivity) { if (adddriverstatedialog == null) { adddriverstatedialog = new adddriverstatedialog(); } adddriverstatedialog.mainactivity = mainactivity; return adddriverstatedialog; } @override public void onresume() { viewgroup.layoutparams params = getdialog().getwindow().getattributes(); params.width = viewgroup.layoutparams.match_parent; getdialog().getwindow().setattributes((android.view.windowmanager.layoutparams) params); super.onresume(); } @override public void oncreate(final bundle savedinstancestate) { super.oncreate(savedinstancestate); // initialise ui elements view = layoutinflater.from(mainactivity).inflate(r.layout.dialog_add_driver_state, null); editabledetails = (linearlayout) view.findviewbyid(r.id.ll_adddriverstate_editabledetails); radiobuttongroup = (radiorealbuttongroup) view.findviewbyid(r.id.radiogroup_dialog_adddriverstate_driverstates); note = (edittext) view.findviewbyid(r.id.et_dialog_adddriverstate_note); et_date = (edittext) view.findviewbyid(r.id.et_dialog_adddriverstate_date); time = (edittext) view.findviewbyid(r.id.et_dialog_adddriverstate_time); odoreading = (edittext) view.findviewbyid(r.id.et_dialog_adddriverstate_odometer); location = (edittext) view.findviewbyid(r.id.et_dialog_adddriverstate_location); insertlog = (checkbox) view.findviewbyid(r.id.chkbox_adddriverstare_insertlog); switchdriver = (checkbox) view.findviewbyid(r.id.chkbox_adddriverstare_switchdriver); radiobutton_offduty = (radiorealbutton) view.findviewbyid(r.id.radiobtn_dialog_adddriverstate_offduty); radiobutton_onduty=(radiorealbutton) view.findviewbyid(r.id.radiobtn_dialog_adddriverstate_onduty); radiobutton_sleeper=(radiorealbutton) view.findviewbyid(r.id.radiobtn_dialog_adddriverstate_sleeperberth); radiobutton_driving=(radiorealbutton) view.findviewbyid(r.id.radiobtn_dialog_adddriverstate_driving); radiobutton_yard=(radiorealbutton) view.findviewbyid(r.id.radiobtn_dialog_adddriverstate_yard_move); radiobutton_personal=(radiorealbutton) view.findviewbyid(r.id.radiobtn_dialog_adddriverstate_personal_conveyance); // initialise data references calendar = calendar.getinstance(); // current datetime , time year = calendar.get(calendar.year); month = calendar.get(calendar.month); day = calendar.get(calendar.date); hours = calendar.get(calendar.hour); minutes = calendar.get(calendar.minute); // initialise data references datepickerdialog = new datepickerdialog(mainactivity, 0, new datepickerdialog.ondatesetlistener() { @override public void ondateset(datepicker view, int year, int month, int dayofmonth) { calendar.set(year, month, dayofmonth); et_date.settext(dateformat.format(calendar.gettime())); } }, year, month, day); timepickerdialog = new timepickerdialog(mainactivity, 0, new timepickerdialog.ontimesetlistener() { @override public void ontimeset(timepicker view, int hourofday, int minute) { calendar.set(calendar.hour_of_day, hourofday); calendar.set(calendar.minute, minute); time.settext(timeformat.format(calendar.gettime())); } }, hours, minutes, false); // ui interaction listeners /* driver state selection listener */ radiobuttongroup.setonclickedbuttonlistener(new radiorealbuttongroup.onclickedbuttonlistener() { @override public void onclickedbutton(radiorealbutton button, int position) { switch (button.getid()) { case r.id.radiobtn_dialog_adddriverstate_offduty: driver_state = driverlog.state_offline; break; case r.id.radiobtn_dialog_adddriverstate_onduty: driver_state = driverlog.state_online; break; case r.id.radiobtn_dialog_adddriverstate_sleeperberth: driver_state = driverlog.state_sleeper; break; case r.id.radiobtn_dialog_adddriverstate_driving: driver_state = driverlog.state_driving; break; case r.id.radiobtn_dialog_adddriverstate_yard_move: driver_state = driverlog.state_yard_move; break; case r.id.radiobtn_dialog_adddriverstate_personal_conveyance: driver_state = driverlog.state_personal_conveyance; break; } } }); et_date.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { datepickerdialog.show(); } }); time.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { timepickerdialog.show(); } }); insertlog.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { editabledetails.setvisibility(view.visible); } else { editabledetails.setvisibility(view.gone); } } }); switchdriver.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { radiobutton_onduty.setvisibility(view.gone); radiobutton_driving.setvisibility(view.gone); radiobutton_yard.setvisibility(view.gone); radiobutton_personal.setvisibility(view.gone); radiobuttongroup.setonclickedbuttonlistener(new radiorealbuttongroup.onclickedbuttonlistener() { @override public void onclickedbutton(radiorealbutton button, int position) { switch (button.getid()) { case r.id.radiobtn_dialog_adddriverstate_offduty: button.setvisibility(view.visible); driver_state = driverlog.state_offline; break; case r.id.radiobtn_dialog_adddriverstate_sleeperberth: button.setvisibility(view.visible); driver_state = driverlog.state_sleeper; break; } } }); } } }); } @nonnull @override public dialog oncreatedialog(bundle savedinstancestate) { return new alertdialog.builder(mainactivity) .settitle("update driver log") .setcancelable(false) .setview(view) .setpositivebutton("accept", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { mainactivity.updatedashboard(driver_state, note.gettext().tostring()); } }) .setnegativebutton("cancel", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dismiss(); } }) .create(); } }
so whant this:
radiobuttongroup.setonclickedbuttonlistener(new radiorealbuttongroup.onclickedbuttonlistener() { @override public void onclickedbutton(radiorealbutton button, int position) { switch (button.getid()) { case r.id.radiobtn_dialog_adddriverstate_offduty: driver_state = driverlog.state_offline; radiobutton_offduty.setenabled(false); radiobutton_onduty.setenabled(true); radiobutton_sleeper.setenabled(true); radiobutton_driving.setenabled(true); radiobutton_yard.setenabled(true); radiobutton_personal.setenabled(true); break; case r.id.radiobtn_dialog_adddriverstate_onduty: driver_state = driverlog.state_online; radiobutton_offduty.setenabled(true); radiobutton_onduty.setenabled(false); radiobutton_sleeper.setenabled(true); radiobutton_driving.setenabled(true); radiobutton_yard.setenabled(true); radiobutton_personal.setenabled(true); break; case r.id.radiobtn_dialog_adddriverstate_sleeperberth: driver_state = driverlog.state_sleeper; radiobutton_offduty.setenabled(true); radiobutton_onduty.setenabled(true); radiobutton_sleeper.setenabled(false); radiobutton_driving.setenabled(true); radiobutton_yard.setenabled(true); radiobutton_personal.setenabled(true); break; case r.id.radiobtn_dialog_adddriverstate_driving: driver_state = driverlog.state_driving; radiobutton_offduty.setenabled(true); radiobutton_onduty.setenabled(true); radiobutton_sleeper.setenabled(true); radiobutton_driving.setenabled(false); radiobutton_yard.setenabled(true); radiobutton_personal.setenabled(true); break; case r.id.radiobtn_dialog_adddriverstate_yard_move: driver_state = driverlog.state_yard_move; radiobutton_offduty.setenabled(true); radiobutton_onduty.setenabled(true); radiobutton_sleeper.setenabled(true); radiobutton_driving.setenabled(true); radiobutton_yard.setenabled(false); radiobutton_personal.setenabled(true); break; case r.id.radiobtn_dialog_adddriverstate_personal_conveyance: driver_state = driverlog.state_personal_conveyance; radiobutton_offduty.setenabled(true); radiobutton_onduty.setenabled(true); radiobutton_sleeper.setenabled(true); radiobutton_driving.setenabled(true); radiobutton_yard.setenabled(true); radiobutton_personal.setenabled(false); break; } } });
Comments
Post a Comment