获取从Custom ArrayAdapter调用的TimePicker中选取的时间

时间:2014-07-14 15:51:12

标签: android android-arrayadapter android-timepicker

我有一个实现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");

            }
        });

如何在数据库中保存小时,因此我需要知道从适配器用户中选择的时间。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

您可以使用SharedPreferences来保存小时和分钟,并随时在intstring中获取 将小时和分钟从Stringint保存到SharedPreferences