I have faced the same problem. I use the other views as the recycler view.
First of all we have to return the two views in getItemViewType().
public int getItemViewType(int position)
{
if(position == 0)
{
return HEADERVIEW;
}
return LISTVIEW;
}
Now, we are adding the other view as the HeaderView in the list so we are going to tweak the list count:
@Override public int getItemCount()
{
return arrayList.size()+1;
}
Now bind the views correctly in onBindViewHolder on the basis on the getItemViewType()
@Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i)
{
if(viewHolder.getItemViewType() == HEADERVIEW )
{
HeaderViewHolder headerViewHolder = (HeaderViewHolder)viewHolder;
headerViewHolder.headertextview.SetText("LongText");
}
else
{
MyHolder myHolder = (MyHolder) viewHolder;
myHolder.name.setText(arrayList.get(i-1).name);
}
Now in the Item Touch Listener Callback we have to tweak the onMove() method:
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
// get the viewHolder's and target's positions in your adapter data, swap them
if(viewHolder.getItemViewType() != target.getItemViewType())
{
return false;
}
int fromPosition = viewHolder.getAdapterPosition();
int toPosition = target.getAdapterPosition();
if(dragFrom == -1)
{
dragFrom = fromPosition;
}
dragTo = toPosition;
if(dragFrom != -1 && dragTo != -1 && dragFrom != dragTo)
{
reallyMoved(dragFrom, dragTo);
dragFrom = dragTo = -1;
}
// and notify the adapter that its dataset has changed
adapter.notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return true;
}
Now if all the logic is right then we move the item and call onreallyMoved() method:
private void reallyMoved(int dragFrom, int dragTo)
{
if(dragFrom == 0 || dragTo == arrayList.size())
{
return;
}
Collections.swap(arrayList, dragFrom-1, dragTo-1);
}
If you want to know more have a look at my blog post.