简体   繁体   中英

swipe cards with recycle view

This not like question its more like discussion

I'm using swipe cards from this library 'link.fls:swipestack:0.3.0'

With the help of these cards i'm creating recycle view on every card but the data is been repeating for every card

i have used adapter to generate cards and inside this adapter i have initialized recycle view

So my question is how to use recycle view with these swipe cards with non repeating values on every card...

这是第一张牌

这是具有相同重复数据的第二张卡片

Thanks in advance

Adapter code

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;
}

}

ParentExamsDataAdapter

public class ParentExamsDataAdapter  extends RecyclerView.Adapter<ParentExamsDataAdapter.MyViewHolder>{
private Context mContext;
private List<List<ParentExams_Pojo>> parentExamsPojoDataList = new ArrayList<>();

public ParentExamsDataAdapter(Context mContext, List<List<ParentExams_Pojo>> parentExamsPojoDataList) {
    this.mContext = mContext;
    this.parentExamsPojoDataList = parentExamsPojoDataList;
}

public class MyViewHolder extends RecyclerView.ViewHolder {
    TextView textView_name;
    TextView textView_date;
    TextView textView_time;
    public MyViewHolder(View itemView) {
        super(itemView);

        textView_name=itemView.findViewById(R.id.singleParentExamsData_txtName);
        textView_date=itemView.findViewById(R.id.singleParentExamsData_txtDate);
        textView_time=itemView.findViewById(R.id.singleParentExamsData_txtTime);
    }
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.single_parent_exams_data, parent, false);
    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    ParentExams_Pojo pojoData=parentExamsPojoDataList.get(position).get(position);
    holder.textView_name.setText(pojoData.getSubjectname()+"-"+pojoData.getSubjectaspectname());
    holder.textView_date.setText(pojoData.getExamdate());
    holder.textView_time.setText(pojoData.getStarttime());
}

@Override
public int getItemCount() {
    return parentExamsPojoDataList.size();
}

}

Basically You have to Set different adapter(ParentExamsDataAdapter(exams[position].getmarks)) inside the getview() method of ParentExamCardAdapter . The problem here is you are sending one instance of adapter to your parent adapter from Activity or Fragment I guess. And you are setting this for every CardAdapter.

Edit: Adding suggested code changes from the comments to the answer.

RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());     
recyclerView.addItemDecoration(new DividerItemDecoration(mContext, LinearLayoutManager.VERTICAL));     
recyclerView.setAdapter(new ParentExamsDataAdapter(**list of items**));

found the solution your are passing same adapter to every recyclerview in every card that is one reason for your problem in ParentExamsCardAdapter recyclerView.setAdapter(dataAdapter); the data adapter is same for every postion the arraylist value is same for aa recyclerview

pass List List ParentExams_Pojo arraylist to ParentExamsCardAdapter use its size in getItemCount then in onbindviewholder use the arraylist.get(position) to pass to adapter then in adapter use List ParentExams_Pojo to get the list and its size in getitemcount it will solve i think

thus you will have only 1 positon in the adapyter ParentExams_Pojo pojoData=parentExamsPojoDataList.get(position)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM