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
Asked
Active
Viewed 59 times
1 Answers
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