I want the date selected by the date picker to displayed on the button which invokes the date picker (through a fragment class). I tried to do this by making a method in the class which defines the action to be taken after the onClick of the button. The method changes the text via setText(). This method is called by the fragment class through the onDateSet() button.
Now when I set the date through the Date picker, the app crashes.
Code:1.
public void onDateSet(DatePicker view, int year, int month, int day) { Addproject changetxt = new Addproject(); changetxt.changebuttontext(year, month, day); //Doing something with the date chosen }
Here the method, which will change the text of the button, from the other class is called and the day, month, year data is passed.
Code 2.
public void changebuttontext (int year, int month, int day) { Button date_button = (Button)findViewById(R.id.datebutton); date_button.setText(year + "/" + month + "/" + day); }
This method is supposed to change the text on the button.
CatLog:
12-24 22:42:25.608: E/AndroidRuntime(3478): at com.kk.project.DatePickerFragment.onDateSet(DatePickerFragment.java:33) 12-24 22:42:25.608: E/AndroidRuntime(3478): at android.app.DatePickerDialog.onClick(DatePickerDialog.java:111) 12-24 22:42:25.608: E/AndroidRuntime(3478): at com.android.internal.app.AlertController$ButtonHandler.handleMessage (AlertController.java:166) 12-24 22:42:25.608: E/AndroidRuntime(3478): at android.os.Handler.dispatchMessage(Handler.java:99) 12-24 22:42:25.608: E/AndroidRuntime(3478): at android.os.Looper.loop(Looper.java:137) 12-24 22:42:25.608: E/AndroidRuntime(3478): at android.app.ActivityThread.main(ActivityThread.java:4424) 12-24 22:42:25.608: E/AndroidRuntime(3478): at java.lang.reflect.Method.invokeNative(Native Method) 12-24 22:42:25.608: E/AndroidRuntime(3478): at java.lang.reflect.Method.invoke(Method.java:511) 12-24 22:42:25.608: E/AndroidRuntime(3478): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 12-24 22:42:25.608: E/AndroidRuntime(3478): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 12-24 22:42:25.608: E/AndroidRuntime(3478): at dalvik.system.NativeStart.main(Native Method)
I have only posted the part which was in red