whalemare whalemare - 4 months ago 63
Android Question

TimePicker not call OnTimeChanged in API-21

I use this code:

public class CustomTimePickerDialog extends TimePickerDialog {
private static final String TAG = CustomTimePickerDialog.class.getSimpleName();


public CustomTimePickerDialog(Context context, OnTimeSetListener listener, int hourOfDay, int minute, boolean is24HourView, String databaseTimeById) {
super(context, listener, hourOfDay, minute, is24HourView);
}

@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
Log.d(TAG, "onTimeChanged");
}


but
onTimeChanged
is not called only in API 21. What could be the problem? Or at least how to do it differently?

I tried extends
MyTimePickerDialog
from
AlertDialog
and setting custom view with TimePicker like this
setView(viewWithTimePicker)
, and then use the method
timePicker.setOnTimeChanged(this)
. It working in API: 23, 22, 16 (!) but not in 21 (Android 5.0). Need help.

Answer

I had same issue with Lolipop so I added

android:timePickerMode="spinner" as timePickerMode and It worked.

<TimePicker
        android:id="@+id/timepick_start"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:timePickerMode="spinner"/>

Try this.