2 xiaoyan 12 xiaoyan_12 于 2013.08.26 14:21 提问

使用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();
        }
    };
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!