如何从Fragment To Activity中使用ArrayList <classobject>

时间:2015-10-19 12:40:42

标签: java android android-fragments arraylist

我想发送ArrayList包含getter setter类对象。但我面临的错误如下:

The method putParcelableArrayListExtra(String, ArrayList<? extends Parcelable>) in the type Intent is not applicable for the arguments (String, ArrayList<BloodDonor>)

//调用新活动

ArrayList<BloodDonor> bloodDonors = filterData(selectedCountry, selectedState, selectedCity, selectedZip, selectedbloodgroup);
Intent intent = new Intent(getActivity(), DonerListActivity.class);
intent.putParcelableArrayListExtra("bloodDonorList", bloodDonors);
startActivity(intent);

// filterData()方法的声明。

private ArrayList<BloodDonor> filterData(String SelectedCountry,
        String selectedState, String selectedCity, String selectedZip,
        String bloodgroup) {

    ArrayList<BloodDonor> bloodDonor = new ArrayList<BloodDonor>();

    Log.d("DB", "values in filter" + SelectedCountry + selectedState
            + selectedCity + selectedZip);

    DatabaseHelperDao helperDao = new DatabaseHelperDao(getActivity());
    try {
        helperDao.open();
        bloodDonor = helperDao.fatchDoner(SelectedCountry,
                selectedState, selectedCity, selectedZip, bloodgroup);
    } catch (Exception e) {
        e.getStackTrace();
    } finally {
        helperDao.close();
    }
    return bloodDonor;

}

dao method fetchdonor()返回捐赠者列表。 请帮帮我。谢谢

1 个答案:

答案 0 :(得分:1)

可能您错过了在Parcelable对象中实现BloodDonor界面。

有关Parcelable的更多信息,您可以找到here