Android RecyclerView with Empty View

Android introduced new view for representing list which is named RecyclerView (android.support.v7.widget.RecyclerView). It should be much better in terms of better design abilities, less device resource usage and others. We decided to use it in new application and all worked pretty well to that point when we start to look to show user information that no item is in list (message or something else). I searched for a solution but actually did not found one that I would appreciate. I will describe what I tried and what I found out.

First I tried to change the layout in RecyclerView.Adapter. There is a method which has to be implemented:

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false);
    return new ViewHolder(view);
}

This could work if you do not use method notifyDataSetChanged() to change items. Then this method is not called and if you have different layouts it would not switch to new layout what would throw exception.

Next approach was to have RecyclerView for lists and TextView to show message on same layout. Depending on if there are any items one is shown and another is hidden. But I have had more problems with layout due to some other elements.

Next solution I found on web (link) gives me what I excepted but I used it in different approach (if you search you will found out many iterations of this solution). They did make own new RecyclerView that would be extended from Android default one. I did not want to override and change the default behavior but it gave me the idea of simple change the adapter for RecyclerView.
I implemented two RecyclerView.Adapter(s). One is used if there are any items and other if there is none. Here is the code for the empty adapter:

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

    private String mMessage;

    public EmptyRecyclerViewAdapter(){}

    public EmptyRecyclerViewAdapter(String message){
        mMessage = message;
    }

    @Override
    public EmptyRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.emty_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);

        if(mMessage != null){
            viewHolder.mMessageView.setText(mMessage);
        }

        return viewHolder;
    }

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

    @Override
    public int getItemCount() {
        return 1;//must return one otherwise none item is shown
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final TextView mMessageView;

        public ViewHolder(View view) {
            super(view);
            mView = view;
            mMessageView = (TextView) view.findViewById(R.id.empty_item_message);
        }
    }
}

And layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="15dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/empty_item_message"
        android:textSize="20dp"
        android:text="@string/empty_item_message"/>

</FrameLayout>

And then I just switch adapters in fragment (same would be in activity) like that:

if (list == null || list.size() == 0){
    mListRecyclerView.setAdapter(mEmptyAdapter);
}else {
    mListRecyclerView.setAdapter(mListAdapter);
    mListAdapter.updateData(list);//here I call notifyDataSetChanged() with new list
}

After testing I found out that in my app it did not influence any performance and for my opinion is the cleanest way to create an empty view. I guess the best way would be if Android's RecyclerView would allow to implement empty view because I think it is used in a lot of scenarios but this is just not the case yet.