Android: How to get the time from a TimePicker when it is typed in

后端 未结 2 1413
轻奢々
轻奢々 2020-12-08 17:42

I\'ve got a DialogPreference which implements a simple TimePicker.OnTimeChangedListener (see below). Setting the time by clicking the +/- buttons works great. But I don\'t k

2条回答
  •  长情又很酷
    2020-12-08 17:47

    Only a very bad workaround so far...

    ViewGroup v = (ViewGroup) timePicker.getChildAt(0);
    ViewGroup numberPicker1 = (ViewGroup) v.getChildAt(0);
    ViewGroup numberPicker2 = (ViewGroup) v.getChildAt(1);
    String hours = ((EditText) numberPicker1.getChildAt(1)).getText().toString();
    String mins = ((EditText) numberPicker2.getChildAt(1)).getText().toString();
    
    selectedTime = hours+":"+mins;
    

提交回复
热议问题