2

i have an activity in which i have an edittext. On click on edittext i want to open TIMEPICKER DIALOG. I had written the code for it and its working. The problem is that when i start the activity and click on edittext for first time-the virtual keyboard opens however for subsequent click on edittext TIMEPICKERDIALOG opens. I do not want virtual keyboard to open even for first time.I want TIMEPICKER DIALOG to open every time. Please help

Here is my code for timepickerdialog to open on edittext click

timeText=(EditText)findViewById(R.id.editText2);

      timeText.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Calendar mcurrentTime = Calendar.getInstance();
                int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
                int minute = mcurrentTime.get(Calendar.MINUTE);

                TimePickerDialog mTimePicker;
                mTimePicker = new TimePickerDialog(RemindDetail.this, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                        timeText.setText( selectedHour + ":" + selectedMinute);
                        calender[3]=selectedHour;
                        calender[4]=selectedMinute;
                    }
                }, hour, minute, false);//Yes 24 hour time
                mTimePicker.setTitle("Select Time");
                mTimePicker.show();

            }
        });

3 Answers3

4

Set this property in your edit text

android:focusable="false"
CodeWarrior
  • 4,248
  • 5
  • 24
  • 41
  • @AndroidWarrior: Thanks, but cursor is not showing. How to include cursor but not keyboard? edit: found the answer [here....](http://stackoverflow.com/questions/13586354/android-hide-soft-keyboard-from-edittext-while-not-losing-cursor) – the_prole Jul 16 '14 at 15:06
0

Hi few days before I was facing the same problem. Then I used onTouchListener on EditText. What it does. it will open your datepicker when someone touch the EditText. use onTouchListener rather then onClickListener on EditText.

you can use this code. which I develop for android xamarin change it for android java. and Extend View.IOnTouchListener

 DOB.SetOnTouchListener (this);


 protected override Dialog OnCreateDialog (int id)
    {

        if (id == DATE_DIALOG_ID) {
            return new DatePickerDialog (this, HandleDateSet, _date.Year,
                _date.Month - 1, _date.Day);
        }
        return null;
    }

    void HandleDateSet (object sender, DatePickerDialog.DateSetEventArgs e)
    {
        _date = e.Date;

        DOB.Text = _date.ToString ("d");
    }



public bool OnTouch(View v, MotionEvent e)
    {
        if (e.Action == MotionEventActions.Up) {
            ShowDialog (DATE_DIALOG_ID);
        }
        return true;

    }

hope it might help you.

suraj shukla
  • 238
  • 3
  • 14
-2

Just set the EditText property like android:focusable="false" in your xml.

Priyanka
  • 751
  • 5
  • 20