我正在尝试构建一个警报时钟应用程序。 TimePicker
正在运行,但如何在选择时间后让它做某事?我正在尝试播放铃声动作。
这是TimePicker
类:
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
private int hours;
private int minutes;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int min = c.get(Calendar.MINUTE);
return new TimePickerDialog(getActivity(), this, hour, min,
DateFormat.is24HourFormat(getActivity()));
}
@Override
public void onTimeSet(android.widget.TimePicker view, int hourOfDay, int minute) {
hours = hourOfDay;
minutes = minute;
if(hours == Calendar.HOUR_OF_DAY && minutes == Calendar.MINUTE){
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getContext(), notification);
r.play();
}
}
}
这是激活TimePicker的按钮:
timePicker = (Button)findViewById(R.id.TimePickerButton);
timePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getFragmentManager(), "pickerTime");
}
});
答案 0 :(得分:0)
您必须删除
if(hours == Calendar.HOUR_OF_DAY && minutes == Calendar.MINUTE){
}