在edittext中设置日期(使用datepicker)后光标不会消失。我希望在设置日期后光标将移动到下一个edittext。这是我设置日期的代码
编辑文本时;静态最终 int DATE_DIALOG_ID = 0;
private int mYear;
private int mMonth;
private int mDay;
//in oncreate
when = (EditText) findViewById(R.id.etDate);
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
when.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_ID);
return false;
}
});
//outside oncreate
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
}
return null;
}
// updates the date in the EditText
private void updateDisplay() {
when.setText(new StringBuilder()
// Month is 0 based so add 1
.append(mDay).append("-").append(mMonth + 1).append("-").append(mYear));
}
// the callback received when the user "sets" the date in the dialog
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
}
};