0

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...

This is first card

This is second card with same repeating data

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

}

Snehal Gongle
  • 337
  • 3
  • 16

2 Answers2

2

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**));
Anand
  • 857
  • 1
  • 12
  • 18
Ajesh R Pai
  • 148
  • 1
  • 7
  • Maybe you are right but that's the hole point of it how do i make multiple adapters because my recycle view is already inside another adpter – Snehal Gongle Jun 23 '18 at 05:43
  • and i dont know how to generate adapter dynamically – Snehal Gongle Jun 23 '18 at 05:48
  • Do one thing, In the GetView method `` – Ajesh R Pai Jun 23 '18 at 15:35
  • `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**)); ` – Ajesh R Pai Jun 23 '18 at 15:37
0

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)

Nadil
  • 56
  • 7
  • i have added it still same response wait ill post adapter code – Snehal Gongle Jun 22 '18 at 05:33
  • its simple recycle view adapter i'm posting it, There you go – Snehal Gongle Jun 22 '18 at 05:45
  • use getitemviewtype inside ParentExamsDataAdapter :) – Nadil Jun 22 '18 at 05:48
  • it didn't work also one thing i want to let you know these cards are making multiple recycle view for every card so the problem is how to differentiate between these cards recycleview and how to apply the proper list to it????? – Snehal Gongle Jun 22 '18 at 05:52
  • i thing problem is in this adapater ParentExams_Pojo pojoData=parentExamsPojoDataList.get(position).get(position); 2 same position – Nadil Jun 22 '18 at 05:57
  • this i have done because i thought it could work with list inside list something like this List>pojo=new ArrayList<>(); so two positions – Snehal Gongle Jun 22 '18 at 06:13
  • pass List> to ParentExamsCardAdapter use its size in getItemCount then in onbindviewholder use the arraylist.get(position) to pass to adapter then in adapter use List and its size it will work – Nadil Jun 22 '18 at 06:20
  • i have checked your edited answer i'm working on it i need little time ill let you know if it works – Snehal Gongle Jun 22 '18 at 06:43
  • i have done as you said now i'm just having problem how to use single adapter with multiple recycle view and the problem is only with onBindViewHolder so i cant differentiate things in onBindHolder so if any suggestions will be really helpful...thanks by the way – Snehal Gongle Jun 22 '18 at 08:08
  • well i dont really get it and dont know how to explain it in words. i guess in List of Lists the outside List is the count of ,no of recyclerviews and inside list is the count of items in recyclerview . so if outside list count is 5 there are 5 recycleview the position in bindholder shows this count . – Nadil Jun 22 '18 at 08:45
  • now then if bindcount is 1 the first recyclerview is got and we need to set data to this recyclerview there , the data to recyclerview is passed in bind holder so each recyclerview get different datas and in thier separate adapters the data of recyclerview will be different based on position. ie inside list in each postion. i dont knw if u get it by this – Nadil Jun 22 '18 at 08:45