EditText pops up TimePicker for Alarm/Reminder System

此生再无相见时 提交于 2019-12-24 11:43:23

问题


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.


回答1:


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.




回答2:


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();

            }
        });


来源:https://stackoverflow.com/questions/17841404/edittext-pops-up-timepicker-for-alarm-reminder-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!