Articles → Android → Timepicker In Android

Timepicker In Android






Purpose





Example






Picture showing the timepicker control inside the constraintlayout
Click to Enlarge



TimePicker MyTimePicker = (TimePicker) findViewById(R.id.MyTimePicker);
MyTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
    @Override
    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
        TextView txtView = (TextView) findViewById(R.id.tvGetDate);

        txtView.setText(hourOfDay + ":" + minute);
    }
});



Output


Picture showing the timepicker control on screen load
Click to Enlarge


Set The Hour And Minute Of Timepicker




TimePicker MyTimePicker = (TimePicker)findViewById(R.id.MyTimePicker);
MyTimePicker.setHour(13);
MyTimePicker.setMinute(22);


Picture showing the selected time in the timepicker control
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, November 25, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250