2016-03-23 128 views

回答

0
public static class TimePickerFragment extends DialogFragment 
          implements TimePickerDialog.OnTimeSetListener { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     // Use the current time as the default values for the picker 
     final Calendar c = Calendar.getInstance(); 
     int hour = c.get(Calendar.HOUR_OF_DAY); 
     int minute = c.get(Calendar.MINUTE); 

     // Create a new instance of TimePickerDialog and return it 
     return new TimePickerDialog(getActivity(), this, hour, minute, 
       DateFormat.is24HourFormat(getActivity())); 
    } 

    public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 
     // Do something with the time chosen by the user 
    } 

要顯示時間選擇器,你分鐘

public void showTimePickerDialog(View v) { 
    DialogFragment newFragment = new TimePickerFragment(); 
    newFragment.show(getSupportFragmentManager(), "timePicker"); 
} 
+0

但用戶界面不類似於我問 –

+0

你是在Android 5.0的工作? –

0

而定。 SDK!如果你有5.0或更多,這個版本有它作爲正常的組件,但如果你有更少的版本,那麼你需要使用一個外部庫。您可以找到這些庫,例如herehere

告訴我,如果我幫你和好的編程!

相關問題