2014-06-22 28 views
0

我想要一個根據時間選擇器而不是數據選擇器設置鬧鐘的應用程序,我希望鬧鐘每天都會在時間選擇器設置爲。根據時間選擇器設置鬧鐘android

我不想有一個按鈕,它變成一個選擇器,我想使用時間選擇器圖標。

回答

0

如果你想有沒有文本的按鈕,你可以使用

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/button_icon" 
... /> 

如果你想建立一個報警創建一個新的類,顯示TimePicker在FragmentDialog

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) { 
     // Here you get the selected Time, do whatever you want 
    } 
} 

而且在活動中,按鈕在哪裏:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/pick_time" 
    android:onClick="showTimePickerDialog" /> 

設置OnclickListener,它使用TimePick啓動FragmentDialog呃

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

http://developer.android.com/guide/topics/ui/controls/pickers.html#TimePicker

我真的不明白,你這是實實在在的。請澄清你的問題。

相關問題