0

enter image description here

Can we use 2 different layouts in Recycler view in android, i want to show listview and gridview on the button clicks, though in both layouts there r diff data item .in list there r 2 textview and in Gridview there is 1 imageview n 2 textviews

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
user271805
  • 11
  • 1

1 Answers1

0

Yes you can try to use the below code in your adapter class. Hope this helps.

   enter code here
  @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,int position)
 {
        final Message message = (Message) getItem(position);
        switch (holder.getItemViewType()) 
{
            case MY_VIEW:
            case Other_View:
                      }
               }

 @Override
    public int getItemViewType(int position)
 {
        Message message = arrayList.get(position);
        if (message.getUsername().equalsIgnoreCase(username)) 
{
            return MY_VIEW;
        }
        return OTHER_VIEW;
    }


      public class ViewHolder2 extends RecyclerView.ViewHolder {


        public ViewHolder2(View v) {
            super(v);


    enter code here
        }


    }

    public class ViewHolder1 extends RecyclerView.ViewHolder {


        public ViewHolder1(View v) {
            super(v);

        }
Daya Nithi
  • 117
  • 1
  • 10
  • Refer https://stackoverflow.com/questions/34385416/how-to-implement-recycler-view-with-multiple-layout?rq=1 – Daya Nithi Jul 20 '17 at 04:29