刷卡与回收视图

时间:2018-06-22 05:02:22

标签: android android-recyclerview swipecardview

这个不喜欢的问题,它更像是讨论

我正在使用来自此库'link.fls:swipestack:0.3.0'的刷卡

借助这些卡,我可以在每张卡上创建回收视图,但是数据在每张卡上都在重复

我已使用适配器生成卡,并且在此适配器内已初始化回收视图

所以我的问题是如何对这些刷卡使用回收视图,每张卡上的值都不重复...

This is first card

This is second card with same repeating data

预先感谢

适配器代码

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});

}

ParentExamsDataAdapter

public class ParentExamsCardAdapter extends BaseAdapter {

private Context mContext;
private List<ParentExamCards_Pojo> parentExamCardsPojoList = new ArrayList<>();

private RecyclerView recyclerView;

private ParentExamsDataAdapter dataAdapter;


public ParentExamsCardAdapter(Context mContext, List<ParentExamCards_Pojo> parentExamCardsPojoList, ParentExamsDataAdapter dataAdapter) {
    this.mContext = mContext;
    this.parentExamCardsPojoList = parentExamCardsPojoList;
    this.dataAdapter = dataAdapter;
}

@Override
public int getCount() {
    return parentExamCardsPojoList.size();
}

@Override
public Object getItem(int i) {
    return i;
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    View itemView = LayoutInflater.from(mContext).inflate(R.layout.single_parent_exams_swipecards, viewGroup, false);

    ParentExamCards_Pojo pojoCards = parentExamCardsPojoList.get(position);

    CardView cardView = itemView.findViewById(R.id.singleParentExamsCards_cardView);
    LinearLayout linearLayout = itemView.findViewById(R.id.singleParentExamsCards_linear);
    TextView textView_Title = itemView.findViewById(R.id.singleParentExamsCards_txtTitle);

    cardView.setBackgroundColor(pojoCards.getColor());
    textView_Title.setText(pojoCards.getExamname());

    recyclerView = itemView.findViewById(R.id.singleParentExamsCards_recycleView);

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new DividerItemDecoration(mContext, LinearLayoutManager.VERTICAL));
    recyclerView.setAdapter(dataAdapter);


    return itemView;
}

@Override
public int getItemViewType(int position) {
    return position;
}

}

2 个答案:

答案 0 :(得分:1)

基本上,您必须在ParentExamCardAdapter的getview方法内设置其他适配器(ParentExamsDataAdapter(exams [position] .getmarks))。问题是我想是从Acitivity或Fragment向您的父适配器发送一个适配器实例。而且您要为每个CardAdapter设置

答案 1 :(得分:0)

找到了将同一适配器传递到每张卡中的每个recyclerview的解决方案,这是您在ParentExamsCardAdapter中遇到问题的原因    recyclerView.setAdapter(dataAdapter); 每个位置的数据适配器都相同 arraylist的值与a recyclerview相同

列表列表ParentExams_Pojo数组列表传递给ParentExamsCardAdapter ,在getItemCount中使用其大小 然后在onbindviewholder中使用arraylist.get(position)传递给适配器,然后在适配器中使用 List ParentExams_Pojo 在getitemcount中获取列表及其大小,它将解决我的想法

因此,您在adapyter中只有1个正子     ParentExams_Pojo pojoData = parentExamsPojoDataList.get(位置)