問題は、インターフェイスを介して FragmentActivityに送信されたInteger
値を取得できないことです。保存された値を取得しようとすると (以下の FragmentActivity を参照)、「incompatible types. Required: java.lang.Integer, Found: 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
}