EditText pops up TimePicker for Alarm/Reminder Sys

2019-08-08 05:06发布

Is it possible to popup a TimePicker when an EditText is clicked/touched?

I've tried looking for examples of this but I haven't found any. I want to use this time entered to set up an alarm, so it'd be great if someone could tell me how to do this and provide me of an example.

I'd prefer it if the Time was in 24 hour format instead of 12 hour format.

Thanks for any answers submitted.

2条回答
时光不老,我们不散
2楼-- · 2019-08-08 05:10

This is the solution. I forgot about the true/false boolean and that's why it wasn't working when I tried something similar to the DatePicker code.

eReminderTime.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(AddReminder.this, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                        eReminderTime.setText( "" + selectedHour + ":" + selectedMinute);
                    }
                }, hour, minute, true);
                mTimePicker.setTitle("Select Time");
                mTimePicker.show();

            }
        });
查看更多
神经病院院长
3楼-- · 2019-08-08 05:37

I will give you some tips to achieve that.

  1. To show popup/dialog after EditText is clicked/touched you will find answer here: Android EditText onClickListener. Also is there discussed if popping dialog after clicking on EditText is standard/non-standard interface.

  2. For TimePicker you can use system TimePickerDialog. You can find tutorial for TimePickerDialog here: http://www.pavanh.com/2013/04/android-timepicker-example.html

  3. To use 24 hour format instead 12 hour format in TimePicker you can use following method: timePicker.setIs24HourView(true), or if you use TimePickerDialog you will pas true in constructor.

Hope it will help you.

查看更多
登录 后发表回答