我有一个实现OnTimeSetListener
的活动,我在其中声明了TimePickerFragment
:
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(),
(MainActivity) getActivity(), hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
}
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
pickerHour = hourOfDay;
pickerMin = minute;
((TextView) findViewById(R.id.textView_hour)).setText(this.pickerHour
+ ":" + this.pickerMin);
}
我从自定义TimePicker
:
ArrayAdapter
TextView hour = (TextView) includeBottom.findViewById(R.id.textView_hour);
hour.setText(Content.FORMAT_HEURES_RAPPEL.format(rappel.getHeure()));
hour.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RappelAdapter.this.runAnimation2(v);
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(((MainActivity)contexte).getSupportFragmentManager(), "timePicker");
}
});
如何在数据库中保存小时,因此我需要知道从适配器用户中选择的时间。我怎么能这样做?
答案 0 :(得分:0)
您可以使用SharedPreferences
来保存小时和分钟,并随时在int
或string
中获取
将小时和分钟从String
或int
保存到SharedPreferences