无法从TimePicker获取小时和分钟

时间:2015-10-15 05:17:39

标签: android

我花时间从gui控制' TimePicker'我试着把这个时间设置在对象上 键入'日历'我从Intent获得(使用Serializable)。

关于方法' public void doneBtnClickEvent(View view)' 我在该行' _calendar.set(Calendar.HOUR,_timePicker.getHour());'

我不明白我做错了什么以及如何解决问题。

public class SetTimeActivicy extends AppCompatActivity {

private TimePicker  _timePicker;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_set_time_activicy);

    _timePicker = (TimePicker)findViewById(R.id.timePicker);

    _timePicker.setIs24HourView(true);

}

public void doneBtnClickEvent(View view) {

    try {

        // exception !! => cant take the Hour and the min
        int h = _timePicker.getHour();
        int m = _timePicker.getMinute();

    }
    catch(Exception e)
    {
        Log.e("Exception - Error ", e.getMessage());
    }



}

}

1 个答案:

答案 0 :(得分:0)

解决了......我用这个

 int hour = _timePicker.getCurrentHour();
 int minute = _timePicker.getCurrentMinute();

方法

int h = _timePicker.getHour();
int m = _timePicker.getMinute();

只是不工作