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've also faced the same problem using API 21, and the problem hasn't been solved yet.
I replaced the TimePicker view for a TimePickerDialog and it worked.
The following code sets a TextView with the time picked from the TimePickerDialog. You can replace the tv.setText() with any logic :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tv = (TextView)findViewById(R.id.textView);
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
tv.setText(String.format(Locale.getDefault(),"Hour: %d, Minute: %d ",hourOfDay,minute));
}
}, hour, minute, true);
timePickerDialog.show();
}