I\'m having some issues implementing a TimePicker in my application that allows the user to change the time of a database record prior to inserting it.
The problem is th
I would like to share my solution as well since the other workarounds posted here doesn't work for me. But I am able to figure it out. This line:
View amPmView = ((ViewGroup)tp.getChildAt(0)).getChildAt(2);
Doesn't seem to return the picker wheel for AM_PM.
NumberPicker amPmView = (NumberPicker ((ViewGroup)tp.getChildAt(0)).getChildAt(3);
Neither this as well, since this one returns a TextView
. It seems it seems it is the label designated on the picker.
But using the latter, getting the 4th child element returns me the picker wheel for AM_PM. Here is what I got so far:
NumberPicker amPmView = (NumberPicker)((ViewGroup) mTimePicker.getChildAt(0)).getChildAt(4);
amPmView.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
{
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
{
Log.i(NoteApplication.TAG, "AM_PM selected...");
}
});
Now I am able to detect changes in AM_PM. I hope this help some other people who can't retrieve it via getChildAt(2)
or getChildAt(3)
as described by other answers.
Also take note that this is the case for the class TimePicker
, I haven't tried this yet on a TimePickerDialog
so I am not sure for that one. I am testing at min sdk 8 targeting api 22.
HTH