handle empty data view in recyclerview
<p>How to handle empty data <code>View</code> in  a <code>RecyclerView</code> ,I have tried so many ways from internet but none seems to work. I am also using realm database so I don't know if this is the right way to check if it is empty or not. </p>

<p>this is my <code>Fragment</code> xml where the <code>RecyclerView</code> is located</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"&gt;

    &lt;TextView
        android:id="@+id/tv_no_data"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_green_dark"
        android:gravity="center"
        android:text="emptty"
        android:textAppearance="?android:textAppearanceMedium"
        android:textColor="@android:color/white"
        android:visibility="invisible" /&gt;

    &lt;android.support.v7.widget.RecyclerView
        android:id="@+id/rv_favorite"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark"&gt;

    &lt;/android.support.v7.widget.RecyclerView&gt;

&lt;/FrameLayout&gt;</code></pre>
</div>
</div>
</p>

<p>and this is my fragment class</p>

<pre><code>public class FavouriteFragment extends Fragment {
RecyclerView mRecyclerView;
FavouriteAdapter adapter;
Realm mRealm;
int positions;
TextView emptyText;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view=inflater.inflate(R.layout.favourite_fragment,container,false);
    mRealm=Realm.getDefaultInstance();
    RealmQuery&lt;news&gt; quotesRealmQuery = mRealm.where(News.class).equalTo("favourite",true);
    RealmResults&lt;News&gt; mResults = newsRealmQuery.findAll();

    emptyText= (TextView) view.findViewById(R.id.tv_no_data);

    //adapter=new FavouriteAdapter(getActivity(),mResults,mRealm);
    mRecyclerView= (RecyclerView) view.findViewById(R.id.rv_favorite);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    if (!mResults.isEmpty()) {
        //if data is available, don't show the empty text
        emptyText.setVisibility(View.INVISIBLE);
        adapter=new FavouriteAdapter(getActivity(),mResults,mRealm,pos,single);
        mRecyclerView.setAdapter(adapter);
        mRealm.addChangeListener(new RealmChangeListener&lt;Realm&gt;() {
            @Override
            public void onChange(Realm element) {
                adapter.notifyItemRemoved(positions);
            }
        });

    } else
        emptyText.setVisibility(View.VISIBLE);




    return view;

}
</code></pre>