1. Ion Carp's Avatar
    I ran not to use two CardView in RecyclerView, who can help me?

    public class RecyclerViewAdaptor extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final int FIRST = 0;
    private static final int SECOND = 1;

    private ArrayList<ProdusSave> arrayList = new ArrayList<>();
    private Context ctx;
    private String name = "dsada";

    public RecyclerViewAdaptor(ArrayList<ProdusSave> arrayList, Context ctx) {
    this.arrayList = arrayList;
    this.ctx = ctx;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    RecyclerView.ViewHolder viewHolder = null;
    if (viewType == SECOND) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_products_save, parent, false);
    // RecyclerViewAdaptor.RecyclerViewHolder recyclerViewHolder = new RecyclerViewAdaptor.RecyclerViewHolder(view, ctx, arrayList);
    // return recyclerViewHolder;
    viewHolder = new RecyclerViewHolder(view, ctx, arrayList);
    } else if (viewType == FIRST) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_products_save_title, parent, false);
    // RecyclerViewAdaptor.RecyclerViewHolderTitle recyclerViewHolder = new RecyclerViewAdaptor.RecyclerViewHolderTitle(view, ctx, arrayList);
    // return recyclerViewHolder;
    viewHolder = new RecyclerViewHolderTitle(view, ctx, arrayList);
    }
    return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    int nType = getItemViewType(position);

    if (nType == SECOND) {
    ProdusSave produsSave = arrayList.get(position);
    RecyclerViewHolder recyclerViewHolder = (RecyclerViewHolder) holder;
    recyclerViewHolder.size.setText(produsSave.getSize_name());
    recyclerViewHolder.color.setText(produsSave.getColor_name());
    recyclerViewHolder.count.setText(String.valueOf(produsSave.getCount_prod()));
    } else {
    ProdusSave produsSave = arrayList.get(position);
    RecyclerViewHolderTitle recyclerViewHolderTitle = (RecyclerViewHolderTitle) holder;
    recyclerViewHolderTitle.title.setText(produsSave.getSize_name());
    recyclerViewHolderTitle.count_final.setText(String.valueOf(produsSave.getCount_final()));
    }

    }

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

    @Override
    public int getItemViewType(int position) {

    int nType = SECOND;

    ProdusSave produsSave = arrayList.get(position);

    if (!(name.equals(produsSave.getName()))) {
    nType = FIRST;
    name = produsSave.getName();
    }
    return nType;
    }

    public class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    private TextView size, color, count;
    private ImageButton up, down, delete;
    private ArrayList<ProdusSave> produsSaves = new ArrayList<>();
    private Context ctx;

    public RecyclerViewHolder(View view, Context ctx, ArrayList<ProdusSave> productses) {

    super(view);
    this.ctx = ctx;
    this.produsSaves = productses;

    size = (TextView) view.findViewById(R.id.size_save);
    color = (TextView) view.findViewById(R.id.color_save);
    count = (TextView) view.findViewById(R.id.count_save);

    up = (ImageButton) view.findViewById(R.id.btn_up_save);
    down = (ImageButton) view.findViewById(R.id.btn_down_save);
    delete = (ImageButton) view.findViewById(R.id.btn_delete_save);

    up.setOnClickListener(this);
    down.setOnClickListener(this);
    delete.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
    int position = getAdapterPosition();
    ProdusSave produsSave = this.produsSaves.get(position);
    switch (view.getId()) {
    case R.id.btn_up_save:
    onDown(view);
    break;
    case R.id.btn_down_save:
    onUp(view);
    break;
    case R.id.btn_delete_save:
    onDelete(view);
    break;
    }
    }

    public void onDown(View view) {

    }

    public void onUp(View view) {

    }

    public void onDelete(View view) {

    }

    }

    class RecyclerViewHolderTitle extends RecyclerView.ViewHolder {

    private TextView title, count_final;
    private ArrayList<ProdusSave> produsSaves = new ArrayList<>();
    private Context ctx;

    public RecyclerViewHolderTitle(View view, Context ctx, ArrayList<ProdusSave> produsSaves) {

    super(view);
    this.ctx = ctx;
    this.produsSaves = produsSaves;

    title = (TextView) view.findViewById(R.id.title_save);
    count_final = (TextView) view.findViewById(R.id.count_final_save);

    }
    }
    }

    I have this error :

    E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.ClassCastException: com.example.ion.pontitestandroid4.Adaptors.RecyclerViewAdaptor$RecyclerViewHolderTitle cannot be cast to com.example.ion.pontitestandroid4.Adaptors.RecyclerViewAdaptor$RecyclerViewHolder
    at com.example.ion.pontitestandroid4.Adaptors.RecyclerViewAdaptor.onBindViewHolder(RecyclerViewAdaptor.java:56)
    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6279)
    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6312)
    at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5258)
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5521)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5363)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5359)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2141)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1525)
    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1488)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:585)
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3506)
    at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2969)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1196)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.widget.ScrollView.onMeasure(ScrollView.java:318)
    at android.view.View.measure(View.java:15172)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
    at android.vie
    12-27-2016 07:15 AM

Similar Threads

  1. how can i sign in with a different account
    By AC Question in forum Ask a Question
    Replies: 2
    Last Post: 12-27-2016, 10:45 AM
  2. cannot update profile picture in messenger on samsung j3
    By AC Question in forum Ask a Question
    Replies: 0
    Last Post: 12-27-2016, 06:38 AM
  3. Replies: 0
    Last Post: 12-27-2016, 05:58 AM
  4. Replies: 0
    Last Post: 12-27-2016, 03:40 AM
  5. Navigation in a new country
    By gautamudaya in forum Ask a Question
    Replies: 0
    Last Post: 12-27-2016, 01:43 AM
LINK TO POST COPIED TO CLIPBOARD