如何显示两次TimePickerDialog?

时间:2016-06-09 07:08:20

标签: android timepickerdialog

我正在使用编译' com.wdullaer:materialdatetimepicker:2.3.0' 库来打开和关闭小时(AM& PM)。我想在用户选择AM之后再次为PM显示TimePickerDialog。然后,我想在TextView上显示AM + PM数据。这是One TimePickerDialog。

layout_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Calendar now = Calendar.getInstance();
                TimePickerDialog tpd = TimePickerDialog.newInstance(
                        MainActivity.this,
                        now.get(Calendar.HOUR_OF_DAY),
                        now.get(Calendar.MINUTE),
                        false
                );
                tpd.show(getFragmentManager(), "Timepickerdialog");
            }
        });

@Override
    public void onResume() {
        super.onResume();
        TimePickerDialog tpd = (TimePickerDialog) getFragmentManager().findFragmentByTag("Timepickerdialog");
        if (tpd != null) tpd.setOnTimeSetListener(this);
    }

@Override
    public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
        String time = hourOfDay + ":" + minute + " am";
        txt_time.setText(time);
    }

2 个答案:

答案 0 :(得分:1)

显示第一个TimePicker方法中的第二个onTimeSet

@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
    String time = hourOfDay + ":" + minute + " am";
    // call the second TimePicker's show() method from here
}

然后,当您同时拥有时,请设置第二个TextView的{​​{1}} TimePicker的{​​{1}}文字。

这样的事情:

onTimeSet

答案 1 :(得分:0)

您必须在onTimeSet方法

中处理该条件
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {

    if(amSelected){
       String amTime = hourOfDay + ":" + minute + " am";
      // call the second TimePicker's show() method from here
    }else if(pmSelected){
      String pmTime = hourOfDay + ":" + minute + " pm";
    }

    if(amSelected && pmSelected){
      //Set Data To textView
      yourtextView.setText(amTime +"-"+pmTime );
    }        

}