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