S.Aofled S.Aofled - 1 year ago 176
Java Question

Android TimePicker at intervals for 5 minutes

My problem is that I need to implement TimePicker at intervals for 5 minutes.

All the examples that I was looking for here

Android - TimePicker minutes to 15

and here

How do i change the Android TimePicker minute intervals?

for me does not work.

If I may, I would like to see a full working example.

This code works, but I do not know how to pass the time here to install, and do not know how to get the time

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {

TimePicker pickStartTime;
TextView textwiew;
private int TIME_PICKER_INTERVAL = 5;
NumberPicker minutePicker;
List<String> displayedValues;

final Calendar cal = Calendar.getInstance();

private int myHourS = cal.get(Calendar.HOUR_OF_DAY);
private int myMinuteS = cal.get(Calendar.MINUTE);

int nextMinute = 0;

protected void onCreate(Bundle savedInstanceState) {
textwiew =(TextView)findViewById(R.id.text1);

pickStartTime = (TimePicker)findViewById(R.id.timePicker1);


private void setTimePickerInterval(TimePicker timePicker) {
try {
Class<?> classForid = Class.forName("com.android.internal.R$id");
// Field timePickerField = classForid.getField("timePicker");

Field field = classForid.getField("minute");
minutePicker = (NumberPicker) timePicker

displayedValues = new ArrayList<String>();
for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) {
displayedValues.add(String.format("%02d", i));
// for (int i = 0; i < 60; i += TIME_PICKER_INTERVAL) {
// displayedValues.add(String.format("%02d", i));
// }
.toArray(new String[0]));
} catch (Exception e) {

public void onClick (View v) {
int Minut = pickStartTime.getCurrentMinute();


Answer Source

do not know how to get the time

Using OnTimeChangedListener

pickStartTime = (TimePicker)findViewById(R.id.timePicker1);
pickStartTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
        Log.d("Time", "You picked "
                + String.valueOf(view.getCurrentHour()) + ":"
                + String.valueOf(view.getCurrentMinute()));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download