系统运行正常。但是无论何时调用此函数并弹出对话框,是否我都没有第一次选择日期,该日期都为null。只有在我再次设置日期后,它才能获取日期。
这是错误'E / ViewRootImpl:sendUserActionEvent()mView == null'
else if(v==editTextDate){
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
day = day + 1;
DatePickerDialog dialog = new DatePickerDialog(MakeResv.this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, mDateSetListener, year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
mDateSetListener = new DatePickerDialog.OnDateSetListener(){
//GET CURRENT DATE
String currentdate = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()).format(new Date());
//SPLIT
String[] items1 = currentdate.split("/");
String dateOnly=items1[0];
String monthOnly=items1[1];
String yearOnly=items1[2];
//convert splited string to integer
int dateOnlyInt = Integer.parseInt(dateOnly);
int monthOnlyInt = Integer.parseInt(monthOnly);
int yearOnlyInt = Integer.parseInt(yearOnly);
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
month = month +1;
Log.d("myTag", "888 "+dayOfMonth + "/" + month + "/" + year );
String date = dayOfMonth + "/" + month + "/" + year;
//editTextDate.setText(date);
if (year<yearOnlyInt||month<monthOnlyInt||dayOfMonth<=dateOnlyInt){
//editTextDate.setError("Invalid year");
Toast.makeText(MakeResv.this,"Invalid date",Toast.LENGTH_SHORT).show();
editTextDate.getText().clear();
editTextDate.setHint("Choose a date");
return;
}else{
editTextDate.setText(date);
}
}
};
}
我希望在“设置”日期后第一次获取日期值。
答案 0 :(得分:0)
您正在使用EditText,这会导致问题。
在EditText上使用TextView。