3
我想在我的自定義對話框中使用日期選擇器。在按鈕上單擊日曆將打開以選擇用戶的日期。我有我的customDilaog類中的按鈕,並在該按鈕上點擊我想打開日曆視圖。點擊此按鈕,我的應用程序崩潰。 我已經完成了這一點。Android中的自定義對話框中的日期選擇器
CustomDialog.java
public class CustomDialog extends Dialog implements android.view.View.OnClickListener {
private Button date;
DateFormat format = DateFormat.getDateInstance();
Calendar calender = Calendar.getInstance();
public CustomDialog(Context context) {
super(context);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
date=(Button)findViewById(R.id.dateText2);
}
public void onClick(View v) {
if (v.getId()==R.id.datePick) {
openDatePicker(v);
//another if-else statements
}
public void updateDate(){
date.setText(format.format(calender.getTime()));
}
public void setDate(){
new DatePickerDialog(getContext(),dp,calender.get(Calendar.YEAR) ,calender.get(Calendar.MONTH),calender.get(Calendar.DAY_OF_MONTH)).show();
}
DatePickerDialog.OnDateSetListener dp = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
calender.set(Calendar.YEAR,year);
calender.set(Calendar.MONTH, monthOfYear);
calender.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateDate();
}
};
}
我不知道我在哪裏出錯了。
郵政錯誤日誌。 – Simas
@Blackbelt openDatePicker是我的onClick xml方法。 –
'錯誤日誌'java.lang.IllegalStateException:無法在活動類中找到方法openDatePicker(View)android.view.ContextThemeWrapper for onClick處理程序查看類android.widget.Button,id爲'dateText2' –