android - Implementing buttons in AlertDialog -
when adding layout buttons alertdialog. doesnt show anything, force stops app. how implement set onclicklistener buttons in alertdialog. want show timepicker on button press
layoutinflater li = layoutinflater.from(this); final view promptsview = li.inflate(r.layout.prompts, null); alertdialog.builder alertdialogbuilder = new alertdialog.builder(this); alertdialogbuilder.setview(promptsview); final edittext userinput = (edittext) promptsview .findviewbyid(r.id.edittextdialoguserinput); starttimebutton=(button)promptsview.findviewbyid(r.id.buttonstarttime); stoptimebutton=(button)promptsview.findviewbyid(r.id.buttonstoptime); starttimebutton.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { toast.maketext(getapplicationcontext(), "btn clocled", toast.length_long).show(); // showdialog(time_dialog_id); } }); stoptimebutton.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { toast.maketext(getapplicationcontext(), "btn clicled", toast.length_long).show(); // showdialog(time_dialog_id); } }); alertdialogbuilder.setcancelable(false).setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int which) { final radiogroup radiogroup = (radiogroup)promptsview.findviewbyid(r.id.radiogroup1); int checkedradiobutton = 0; try { checkedradiobutton = radiogroup.getcheckedradiobuttonid(); } catch (exception e) { e.printstacktrace(); } int i=0; togglelogging(appsettings.getservicerunning(mainactivity.this), appsettings.setlogginginterval(mainactivity.this,currentintervalchoice)); dialog.dismiss(); // return; } }); // create alert dialog alertdialog alertdialog = alertdialogbuilder.create(); // show alertdialog.show(); this: <button android:id="@+id/buttonstarttime" android:layout_width="wrap_content" android:layout_height="30dp" android:text="set start time" /> <textview android:id="@+id/starttime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="starttime" android:textappearance="?android:attr/textappearancesmall" /> <button android:id="@+id/buttonstoptime" android:layout_width="wrap_content" android:layout_height="30dp" android:text="set stop time" />
obj.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { // if button clicked, close } });
Comments
Post a Comment