android - Date Picker Dialog using Xamarin -
i'm developing android application using xamarin , want set date on edittext field using datepicker. when click on edittext datepicker opens when date set date not shown on edittext. wrong in provided code.
thanks in advance.
public class pagefragment : android.support.v4.app.fragment { int _num; database baseobj = new database(); edittext datepickertext; datepickerdialog date; view v; public pagefragment() { } public pagefragment(int num) { // supply num input argument. var args = new bundle(); args.putint("num", num); arguments = args; } public override void oncreate(bundle savedinstancestate) { base.oncreate(savedinstancestate); _num = arguments != null ? arguments.getint("num") : 1; } public override view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { v = inflater.inflate(resource.layout.distribution, container, false); datepickertext = v.findviewbyid<edittext>(resource.id.edittextcalender); datepickertext.focusable = false; datepickertext.click += delegate { var dialog = new datepickerdialogfragment(activity, datetime.now, null); dialog.show(fragmentmanager, "date"); }; return v; } public void ondateset(android.widget.datepicker view, int year, int monthofyear, int dayofmonth) { v.findviewbyid<edittext>(resource.id.edittextcalender).text = new datetime(year, monthofyear + 1, dayofmonth).tostring(); } public class datepickerdialogfragment : android.support.v4.app.dialogfragment { private readonly context _context; private datetime _date; private readonly datepickerdialog.iondatesetlistener _listener; public datepickerdialogfragment(context context, datetime date, datepickerdialog.iondatesetlistener listener) { _context = context; _date = date; _listener = listener; } public override dialog oncreatedialog(bundle savedstate) { var dialog = new datepickerdialog(_context, _listener, _date.year, _date.month - 1, _date.day); return dialog; } } }
i know quite late answer problem. hope have solved problem though. have got answer why edittextcalender can not show date set through datepickerdialog. got change following lines of code
public void ondateset(android.widget.datepicker view, int year, int monthofyear, int dayofmonth) { v.findviewbyid<edittext>(resource.id.edittextcalender).text = new datetime(year, monthofyear + 1, dayofmonth).tostring(); }
into(correct one)
public void ondateset(android.widget.datepicker view, int year, int monthofyear, int dayofmonth) { datepickertext.text = new datetime(year, monthofyear + 1, dayofmonth).tostring(); }
because have inflated datepickertext = v.findviewbyid<edittext>(resource.id.edittextcalender);
while creating view before handle click event on it.
thank you!
Comments
Post a Comment