Example usage for android.widget TimePicker findViewById

List of usage examples for android.widget TimePicker findViewById

Introduction

In this page you can find the example usage for android.widget TimePicker findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:edu.pdx.its.portal.routelandia.DatePickUp.java

/**
 * change the minute interval to quarter*
 * @param timePicker : timepicker obk in the view
 *//*from w  w w .ja  v  a 2  s.  c  o m*/
@SuppressLint("NewApi")
private void setTimePickerInterval(TimePicker timePicker) {
    try {
        Class<?> classForid = Class.forName("com.android.internal.R$id");

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

        minutePicker.setMinValue(0);
        minutePicker.setMaxValue(7);
        ArrayList<String> displayedValues = new ArrayList<>();
        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));
        }
        minutePicker.setDisplayedValues(displayedValues.toArray(new String[0]));
    } catch (Exception e) {
        e.printStackTrace();
    }
}