-1

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?

2 Answers2

0

Have you tried using

<uses-permission android:name="android.permission.VIBRATE" />

on your manifest?

iluretar
  • 3
  • 3
0

I believe you are forgetting to get a string conversion value.

 dateValue.setText(getString(R.string.calendar_date_picker_result_values, year, monthOfYear, dayOfMonth));

where by the string value is:

<string name="calendar_date_picker_result_values">Year: %1$s Month: %2$s Day: %3$s</string>
jeanluc rotolo
  • 165
  • 1
  • 11