0

问题是我无法从通过接口发送到 FragmentActivity的值中检索Integer值。当我尝试获取保存的值时(请参阅下面的 FragmentActivity),我得到“不兼容的类型。必需:java.lang.Integer,找到:java.lang.Object”。ArrayList<Integer>TimePickerFragment

时间选择器片段:

public class TimePickerFragment extends DialogFragment
    implements TimePickerDialog.OnTimeSetListener {

Listener mListener;

// declaration of the interface
public interface Listener {
    public void onUserTimeChoice(ArrayList dataSet);
}


// registration of the listener
public void registerListener(Listener listener) {
    mListener = listener;
}


@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) {
    // Do something with the time chosen by the user
    ArrayList<Integer> mAList = new ArrayList();

    mAList.add(hourOfDay);
    mAList.add(minute);
    mListener.onUserTimeChoice(mAList);
}
}

FragmentActivity(摘录):

@Override
public void onUserTimeChoice(ArrayList dataSet) {

    Integer hour = dataSet.get(0);   //  <--- incompatible types
    Integer minute = dataSet.get(1); // <--- incompatible types

}
4

1 回答 1

4

使用泛型类型而不是原始类型。相当于dataSetArrayList dataSetArrayList<Object> dataSet

使用 aList而不是 an向接口添加代码ArrayList

public void onUserTimeChoice(List<Integer> dataSet) {
于 2013-09-19T13:57:55.863 回答