java - Android DatePicker showing Full Screen on Initialization -
i have followed this tutorial integrate datepicker app, have tailored original suit needs , managed working. unfortunately author doesn't go concepts of using datepicker dialog.
as result, full screen calendar shown when app launched, whereas trying pull day, month , year when button 'pick date' clicked, need remove?
code here:
public class mainactivity extends activity implements onclicklistener, oncheckedchangelistener { tabhost th; button changedate; textview displaydate; public static final int ddialogid = 1; // date , time private int myear; private int mmonth; private int mday; @override protected void oncreate(bundle savedinstancestate) { // set activity full screen!! requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); th = (tabhost) findviewbyid(r.id.tabhost); th.setup(); tabspec specs = th.newtabspec("tag1"); // 1 tab specs.setcontent(r.id.tab1); // appears on actual tab specs.setindicator("tools"); th.addtab(specs); specs = th.newtabspec("tag2"); // 1 tab specs.setcontent(r.id.tab2); // appears on actual tab specs.setindicator("calorie calculator"); th.addtab(specs); specs = th.newtabspec("tag3"); // 1 tab specs.setcontent(r.id.tab3); // appears on actual tab specs.setindicator("your stats!"); th.addtab(specs); initializevariables(); } private void initializevariables() { maparun = (button) findviewbyid(r.id.btnmaparun); weightconverter = (button) findviewbyid(r.id.btnweightconverter); changedate = (button) findviewbyid(r.id.btnchangedate); displaydate = (textview) findviewbyid(r.id.tvdisplaydate); changedate.setonclicklistener(this); final calendar c = calendar.getinstance(); myear = c.get(calendar.year); mmonth = c.get(calendar.month); mday = c.get(calendar.day_of_month); updatedisplay(); } @override @deprecated protected void onpreparedialog(int id, dialog dialog) { // todo auto-generated method stub super.onpreparedialog(id, dialog); ((datepickerdialog) dialog).updatedate(myear, mmonth, mday); } private datepickerdialog.ondatesetlistener mdatesetlistener = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { myear = year; mmonth = monthofyear; mday = dayofmonth; updatedisplay(); } }; private void updatedisplay() { displaydate.settext(new stringbuilder() // month 0 based add 1 .append(mmonth + 1).append("-").append(mday).append("-") .append(myear)); } @override public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub } } @override public void onclick(view v) { switch (v.getid()) { case r.id.btnchangedate: datepickerdialog dpd = new datepickerdialog(this, mdatesetlistener, myear, mmonth, mday); dpd.show(); break; } } } }
apologies if hit syntax errors when codei s run, cut out lot of other, unrelated functions,
is there way show datepicker when dialog called?
create yout main category button. make button call activity code. you'll screen button calls screen fullscreen datepicker.
make datepicker activity end when date selected. make sure calling activity startactivityforresult , end finishwithresult.
Comments
Post a Comment