Android Date Picker not working properly -
i trying implement date picker in android. datepicker should appear after tapping on button. yeah,i know it's pretty straightforward being beginner, bit stuck in this. here parts of code relevant task.
public class needfragment extends fragment { private datepicker datepicker; private calendar calendar; private textview dateview; private int year, month, day; fragment fragment; string selecteddate=null; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_need_blood, container, false); button button1 = (button)rootview.findviewbyid(r.id.dialog_btn1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { getactivity().showdialog(999); if(selecteddate != null) { log.d("date",selecteddate); } //openappointments(dialog); } }); return rootview; } protected dialog oncreatedialog(int id) { // todo auto-generated method stub if (id == 999) { return new datepickerdialog(getactivity().getapplicationcontext() , 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 stringbuilder sb=null; sb.append(arg3).append("/") .append(arg2+1).append("/").append(arg1); returndate(sb.tostring()); } }; public void returndate(string s) { selecteddate=s; } }
this error:
06-25 15:19:53.150: e/androidruntime(13160): fatal exception: main 06-25 15:19:53.150: e/androidruntime(13160): process: com.bloodbank.slidingmenu, pid: 13160 06-25 15:19:53.150: e/androidruntime(13160): java.lang.nullpointerexception: println needs message 06-25 15:19:53.150: e/androidruntime(13160): @ android.util.log.println_native_inner(native method) 06-25 15:19:53.150: e/androidruntime(13160): @ android.util.log.println_native(log.java:290) 06-25 15:19:53.150: e/androidruntime(13160): @ android.util.log.d(log.java:323) 06-25 15:19:53.150: e/androidruntime(13160): @ com.bloodbank.slidingmenu.needbloodfragment$3.onclick(needbloodfragment.java:220) 06-25 15:19:53.150: e/androidruntime(13160): @ android.view.view.performclick(view.java:4761) 06-25 15:19:53.150: e/androidruntime(13160): @ android.view.view$performclick.run(view.java:19767) 06-25 15:19:53.150: e/androidruntime(13160): @ android.os.handler.handlecallback(handler.java:739) 06-25 15:19:53.150: e/androidruntime(13160): @ android.os.handler.dispatchmessage(handler.java:95) 06-25 15:19:53.150: e/androidruntime(13160): @ android.os.looper.loop(looper.java:135) 06-25 15:19:53.150: e/androidruntime(13160): @ android.app.activitythread.main(activitythread.java:5312) 06-25 15:19:53.150: e/androidruntime(13160): @ java.lang.reflect.method.invoke(native method) 06-25 15:19:53.150: e/androidruntime(13160): @ java.lang.reflect.method.invoke(method.java:372) 06-25 15:19:53.150: e/androidruntime(13160): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) 06-25 15:19:53.150: e/androidruntime(13160): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696)
edit: previous error resolved. have 1 more question though. can start activity after click on ok in date dialog box?
once change following line
getactivity().showdialog(999);
to
dialog dialog=oncreatedialog(999); if(dialog!=null){ dialog.show(); }
Comments
Post a Comment