我正在使用betterspickers库。我试图实施calendardatepicker。它会打开选择器对话框,但是当我点击应用程序崩溃的几个月中的某一天时。 这是我的班级:
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);
}
}
}
你能帮我吗?
答案 0 :(得分:0)
您是否尝试过使用
<uses-permission android:name="android.permission.VIBRATE" />
你的清单上有吗?
答案 1 :(得分:0)
我相信你忘了获得字符串转换值。
dateValue.setText(getString(R.string.calendar_date_picker_result_values, year, monthOfYear, dayOfMonth));
其中字符串值为:
<string name="calendar_date_picker_result_values">Year: %1$s Month: %2$s Day: %3$s</string>