根据android中的timepicker设置闹钟

时间:2014-06-22 13:03:37

标签: android alarm timepicker

我想要一个根据时间选择器而不是数据选择器设置闹钟的应用程序,我希望闹钟在设置时间选择器时每天都会关闭。

我不希望有一个按钮成为我想要使用时间选择器图标的选择器。

1 个答案:

答案 0 :(得分:0)

如果您想要一个没有文字的按钮,可以使用

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

如果要设置一个Alarm创建一个新类,它在FragmentDialog中显示TimePicker

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,它使用TimePicker启动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

我真的不明白,你究竟要求的是什么。请澄清你的问题。