2015-06-03 51 views
0

對不起,我的英語。我想如果單擊textView打開對話框並設置時間(24小時),但我無法獲得價值。 Log.e輸出什麼StartTimePicker設置時間(android)

time.setOnClickListener(new OnClickListener() { 
      @SuppressLint("NewApi") @Override 
      public void onClick(View v) { 
       DialogFragment dialogFragment = new StartTimePicker(); 
       dialogFragment.show(getFragmentManager(), "start_t_picker"); 
      } 
     }); 

//code 
@SuppressLint("NewApi") 
     class StartTimePicker extends DialogFragment implements OnTimeSetListener{ 

      @Override 
      public Dialog onCreateDialog(Bundle savedInstanceState) { 
       TimePickerDialog dialog = new TimePickerDialog(Send.this, null, hour, min, true); 

       return dialog; 
      } 


      @Override 
      public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 

       Log.e("time is", String.valueOf(hourOfDay) + ":" + String.valueOf(minute)); 

      } 
     } 

回答

1

更改您的onCreateDialog()方法,該

  @Override 
      public Dialog onCreateDialog(Bundle savedInstanceState) { 
       TimePickerDialog dialog = new TimePickerDialog(Send.this, this, hour, min, true); 

       return dialog; 
      } 
+0

感謝狀,但不工作( – mzb86604

+0

uuupppssss,它的工作,謝謝! – mzb86604