问题描述
- 使用datepicker设置日期后为什么隐藏editetext的光标?
-
在editetext中使用datepicker设置日期后,光标就不显示了。我想实现的是设置完日期,光标就会移动到下一个edittext。
设置日期的代码:EditText when; static final 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(); } };
时间: 2025-01-02 06:11:47