android - AlertDialog not working in a Fragment -
hello i'm doing app in button pressed , alertdialog window pops timepicker. in fragment appcompatactivity not do.
fragment itself:
public class time_change extends fragment implements timepickerfragment.timedialoglistener { private static final string dialog_time = "mainactivity.timedialog"; private view v; private button timepickeralertdialog; private imagebutton back; @override @nullable public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { v = inflater.inflate(r.layout.pamokos, container, false); timepickeralertdialog = (button) v.findviewbyid(r.id.alert_dialog_time_picker); timepickeralertdialog.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { timepickerfragment dialog = timepickerfragment.newinstance(); dialog.show(getactivity().getfragmentmanager(), "timepickerfragment"); } }); = (imagebutton) v.findviewbyid(r.id.back_btn1); back.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { pamokos fr = new pamokos(); time_change fr2 = new time_change(); android.app.fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.replace(r.id.activity_frag, fr); fragmenttransaction.remove(fr2); fragmenttransaction.addtobackstack(null); fragmenttransaction.commit(); } }); return v; } @override public void onfinishdialog(string time) { toast.maketext(getactivity(), "selected time : " + time, toast.length_short).show(); } }
but shows error at
dialog.show(getactivity().getfragmentmanager(), "timepickerfragment");
saying "cannot resolve method 'show(android.app.fragmentmanager, java.lang.string)'"
full code tutorial https://www.androidtutorialpoint.com/basics/android-alert-dialog-tutorial-working-time-picker-date-picker-list-dialogs/
i'm quite lost.
replace
timepickerfragment dialog = timepickerfragment.newinstance(); dialog.show(getactivity().getfragmentmanager(), "timepickerfragment");
with this
fragmentmanager fm = getactivity().getsupportfragmentmanager(); timepickerfragment dialog = new timepickerfragment (); dialog.show(fm, "timepickerfragment");
Comments
Post a Comment