Android: Focus on TimePicker elements
Asked Answered
G

2

6

How to get focus on time picker elements? I am developing TV app, so it needs to be operated by remote. So I need to apply focus on each element. TimePicker has 3 elements - hour column, minutes column and AM/PM column.

So how do i get focus on each of these 3 columns?

Thanks

Gere answered 4/3, 2015 at 15:29 Comment(0)
R
7

You can get each NumberPicker of TimePicker and make whatever you want such as modify, request the focus and so on.

NumberPicker hourPicker = (NumberPicker) mTimePicker.findViewById(Resources.getSystem().getIdentifier("hour",
     "id", "android"));

NumberPicker minutePicker = (NumberPicker) mTimePicker.findViewById(Resources.getSystem().getIdentifier("minute",
     "id", "android"));

NumberPicker amPmPicker = (NumberPicker) mTimePicker.findViewById(Resources.getSystem().getIdentifier("amPm",
     "id", "android"));

// this is a number picker modified and there is one for each NumerPicker above
View numberPickerModified = (View) mTimePicker.findViewById(Resources.getSystem().getIdentifier("numberpicker_input",
     "id", "android"));
Review answered 10/3, 2015 at 12:54 Comment(4)
Hi, can you please explain how i can use addfocusables on timerpicker?Gere
It's better you make different than I said. Please take a look again what I've editedReview
the above assumes spinner mode (TimePickerSpinnerDelegate), the names of these views change and they are TextViews in clock mode (TimePickerClockDelegate), check the sourceEidson
@HMaclean yeah. Your must edit according to the target you are working onReview
C
1

So the class has since changed and the above did not work for me.

One reason was the view is not a number picker when in clock mode and the second that they have changed the views name.

Here is the Kotlin solution for hours.

 val identifier = Resources.getSystem().getIdentifier(
            "hours",
            "id", "android"
        )
 val hourPicker = itemView.findViewById<TextView>(identifier)

The view is a TextView and the identifier is 'hours' not 'hour'

Cucumber answered 30/7, 2020 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.