3 回答
TA贡献1848条经验 获得超2个赞
解决方案
在解决之前,这个崩溃的问题是recyclerview temp size的hashmap列表和列表类不同。我在这里使用嵌套数组列表 。
我从@Suraj Vaishnav 找到了这个解决方案。1. 获取来自solidatedList 的数据,因为这个数组被传递给了适配器。2. 为consolidatelist >= position 创建Condition 3. 放置Extra 并创建GeneralItem 对象,并从中获取数据。
mRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(getContext(), mRecyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
if(consolidatedList.size()-1 >= position)
{
GeneralItem generalItem = (GeneralItem) consolidatedList.get(position);
Intent intent = new Intent(getActivity(), DetailPengumuman.class);
intent.putExtra("namamatkul", generalItem.getDaftarPengumuman().getNama_p());
intent.putExtra("tanggalpengumuman", generalItem.getDaftarPengumuman().getTanggal_peng());
intent.putExtra("judulpengumuman", generalItem.getDaftarPengumuman().getJudul());
intent.putExtra("deskripsipengumuman", generalItem.getDaftarPengumuman().getDeskripsi());
startActivity(intent);
}
}
@Override
public void onLongClick(View view, int position) {
}
}));
TA贡献1946条经验 获得超4个赞
试试这个代码来获取数据。
Object data = consolidatedList.get(position);
if (data instanceof GeneralItem){
DaftarPengumuman pengumuman = data.getDaftarPengumuman();
}
TA贡献1963条经验 获得超6个赞
position 参数是在回收器视图中单击的项目的索引,此处不应使用 position-1。只需使用位置。另一件事是DaftarPengumuman pengumuman = listPengumuman.get(position-1);这可能工作正常。但在这些陈述中:
intent.putExtra("namamatkul", namaMatkulPut.get(position-1));
intent.putExtra("namapengumuman", namaPengumumanPut.get(position-1));
intent.putExtra("tanggalpengumuman", tanggalPengumumanPut.get(position-1));
intent.putExtra("judulpengumuman", judulPengumumanPut.get(position-1));
intent.putExtra("deskripsipengumuman", deskripsiPengumumanPut.get(position-1));
您对不同的数组使用相同的参数(位置)。确保它们每个都具有相同的尺寸。
- 新的 - -
问题是综合列表大小和列表企鹅不一样。
为了避免这种崩溃,您可以执行以下操作:
if(listPengumuman.size()-1 >= position)
{
DaftarPengumuman pengumuman = listPengumuman.get(position);
}
添加回答
举报