Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Focus on TimePicker elements

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

like image 997
Gaurav Avatar asked Mar 04 '15 15:03

Gaurav


People also ask

How picker views are used in Android application?

Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).

How time picker is used to set an alarm explain?

Android Time Picker allows you to select the time of day in either 24 hour or AM/PM mode. The time consists of hours, minutes and clock format. Android provides this functionality through TimePicker class.


2 Answers

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"));
like image 179
Lennon Spirlandelli Avatar answered Sep 28 '22 18:09

Lennon Spirlandelli


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'

like image 31
badvok Avatar answered Sep 28 '22 18:09

badvok