I'm using the betterspickers library . i'm trying to implement the calendardatepicker. It opens the picker dialog but when I click on one of the days of the months the app crashes. here is my class:
public class AddOneActivity extends ActionBarActivity implements CalendarDatePickerDialog.OnDateSetListener {
private static final String FRAG_TAG_DATE_PICKER = "fragment_date_picker_name";
private TextView text;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_one);
DateTime now = DateTime.now();
text = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
text.setText(now.getDayOfMonth()+"."+now.getMonthOfYear()+"."+now.getYear());
button.setText("Set Date");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
DateTime now = DateTime.now();
CalendarDatePickerDialog calendarDatePickerDialog = CalendarDatePickerDialog
.newInstance(AddOneActivity.this, now.getYear(), now.getMonthOfYear() - 1,
now.getDayOfMonth());
calendarDatePickerDialog.show(fm, FRAG_TAG_DATE_PICKER);
}
});
}
@Override
public void onDateSet(CalendarDatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) {
text.setText("Year: " + year + "\nMonth: " + monthOfYear + "\nDay: " + dayOfMonth);
}
@Override
public void onResume() {
// Example of reattaching to the fragment
super.onResume();
CalendarDatePickerDialog calendarDatePickerDialog = (CalendarDatePickerDialog) getSupportFragmentManager()
.findFragmentByTag(FRAG_TAG_DATE_PICKER);
if (calendarDatePickerDialog != null) {
calendarDatePickerDialog.setOnDateSetListener(this);
}
}
}
can you please help me?