android - How to use DialogFragment for Date Picker in Fragment (onCreateDialog not used) -
i have done little research in dialogfragment , using fragment oncreate dialog not work. understand there documentation
http://developer.android.com/reference/android/app/dialogfragment.html#alertdialog
although new android programming , not easy understand code involved unless relates doing, below class have problems with:
public class addfixture extends fragment { public addfixture() { } private datepicker datepicker; private calendar calendar; private textview dateview; private int year, month, day; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); sethasoptionsmenu(true); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.add_fixture, container, false); } @override public void onviewcreated(view view, bundle savedinstancestate) { add_date = (button) view.findviewbyid(r.id.datebutton); dateview = (textview) view.findviewbyid(r.id.dateselected); calendar = calendar.getinstance(); year = calendar.get(calendar.year); month = calendar.get(calendar.month); day = calendar.get(calendar.day_of_month); showdate(year, month + 1, day); //call setdate method setdate(); @suppresswarnings("deprecation") public void setdate() { add_date.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { getactivity().showdialog(999); toast.maketext(getactivity().getapplicationcontext(), "ca", toast.length_short) .show(); } }); } //oncreatedialog depreciated @override protected dialog oncreatedialog(int id) { // todo auto-generated method stub if (id == 999) { return new datepickerdialog(getactivity(), mydatelistener, year, month, day); } return null; } private datepickerdialog.ondatesetlistener mydatelistener = new datepickerdialog.ondatesetlistener() { @override public void ondateset(datepicker arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub // arg1 = year // arg2 = month // arg3 = day showdate(arg1, arg2 + 1, arg3); } }; private void showdate(int year, int month, int day) { dateview.settext(new stringbuilder().append(day).append("/") .append(month).append("/").append(year)); } @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { getactivity().getmenuinflater().inflate(r.menu.main, menu); super.oncreateoptionsmenu(menu, inflater); } }
Comments
Post a Comment