keypad appears first time , then second time when clicked timepicker dialog appears android

StackOverflow https://stackoverflow.com/questions/22276681

  •  11-06-2023
  •  | 
  •  

Question

When user clicks the edtText the first time the keypad appears, the user needs to click another time so the dialog appears. Even while debugging it reaches the show method of the timePickerDialog, but still on the first time the keypad appears, on the second click the dialog appears

public class NewAssignment extends FragmentActivity implements DatePickerDialog.OnDateSetListener,
        TimePickerDialog.OnTimeSetListener
{
         EditText  timePicker;

        timePicker = (EditText) findViewById(R.id.timePicker);
    timePicker.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                showTimePickerDialog();

            }
        });

public void showTimePickerDialog()
    {

        final Calendar c = Calendar.getInstance();
        int hourOfDay = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        TimePickerDialog td = new TimePickerDialog(this, this, hourOfDay, minute, DateFormat.is24HourFormat(this));
        td.show();

    }
     }
Était-ce utile?

La solution

i encountered the same problem, while implementing time and date pickers. following code did it for me

timePicker.setInputType(InputType.TYPE_NULL);

but then you would have to click twice to make the time picker dialog appear. so add

timePicker.setFocusable(false);

and everything should work as expected.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top