Android 时间对话框 TimePickerDialog

    private int hourOfDay, minute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.button);

        Calendar calendar = Calendar.getInstance();
        hourOfDay = calendar.get(Calendar.HOUR);
        minute = calendar.get(Calendar.MINUTE);

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                TimePickerDialog pickerDialog = new TimePickerDialog(MainActivity.this, new OnTimeSetListener() {

                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        // TODO Auto-generated method stub
                        Toast.makeText(MainActivity.this, hourOfDay + "时" + minute + "分", 1).show();
                        ;
                    }
                }, hourOfDay, minute, true);

                pickerDialog.show();
            }
        });
    }

image

image

posted @ 2019-11-05 15:43  thomas_blog  阅读(2989)  评论(0编辑  收藏  举报