JavaMan
JavaMan

Reputation: 87

Programmatically change selecting view (hour/minute) in TimePicker

I am wondering how to change selecting view in TimePicker. For example: I am at minute view and click some button and view change to selecting hour.

. I am using custom Timepicker class with TimePicker in layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
style="@style/AppTheme"
android:background="@color/colorPrimaryDark">

<TimePicker
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tp_timepicker"
    android:layout_weight="1" />
 </LinearLayout>

Upvotes: 4

Views: 1192

Answers (1)

Tom Ladek
Tom Ladek

Reputation: 817

Since requesting focus on the text views of the time picker didn't work, I went with performing the click on them - worked for me!

TimePicker tp = parentView.findViewById(R.id.tp_timepicker)
View timePickerPart = tp.findViewById(Resources.getSystem().getIdentifier("hours", "id", "android"));
timePickerPart.performClick();

Also works for minutes instead of hours. May work for amPm, too.

Upvotes: 3

Related Questions