Snackbar in a particular fragment
<p>I have 5 sliding tabs in a <code>ViewPager</code>, each holding a different fragment. If the data fails to load, I want to notify the user via Snackbar. It's working fine.</p>

<p>What I'm trying to achieve is, if data fails to load in a particular fragment, I want to show a <code>Snackbar</code> in that particular fragment only. Is it possible? </p>

<blockquote>
  <p>I'll elaborate:</p>
</blockquote>

<p>Consider a sliding tab layout with 3 fragments as A, B, &amp; C. All 3 fragments perform some network query and load the data. If due to some reason data fails to load in fragment A, a snackbar should be shown indefinitely. And if the user slides to fragment B (in which data loaded successfully), snackbar should not be visible. </p>

<p>So the snackbar should only be visible in the fragment which failed to load data.</p>

<blockquote>
  <p>Fragment Code:</p>
</blockquote>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_latest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/windowBackground"
tools:context=".MainFragment"&gt;

&lt;android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;

    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"&gt;

        &lt;LinearLayout
            android:id="@+id/date_layout"
            android:visibility="gone"
            android:layout_gravity="center_horizontal"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"&gt;

            &lt;android.support.v7.widget.AppCompatSpinner
                android:id="@+id/country_select"
                style="@style/Base.Widget.AppCompat.Spinner.Underlined"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:entries="@array/country"
                /&gt;

            &lt;android.support.v7.widget.AppCompatSpinner
                android:id="@+id/month_select"
                style="@style/Base.Widget.AppCompat.Spinner.Underlined"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:entries="@array/month"
                /&gt;

            &lt;android.support.v7.widget.AppCompatSpinner
                android:id="@+id/year_select"
                style="@style/Base.Widget.AppCompat.Spinner.Underlined"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:entries="@array/year"
                /&gt;

        &lt;/LinearLayout&gt;

        &lt;android.support.v7.widget.RecyclerView
            android:id="@+id/latest_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" /&gt;

    &lt;/LinearLayout&gt;

&lt;/android.support.v4.widget.SwipeRefreshLayout&gt;

&lt;LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"&gt;

    &lt;TextView
        android:id="@+id/not_available"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-medium"
        android:gravity="center"
        android:textSize="16sp" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p></p>

<blockquote>
  <p>Snackbar Code:</p>
</blockquote>

<pre><code>if (Utils.isNetworkAvailable(getActivity())) {
        adapter.notifyDataSetChanged();
        loadData();
    } else {
        swipeRefreshLayout.setRefreshing(false);
        textView.setText(getString(R.string.check_internet));
        Snackbar.make(frameLayout, "Loading failed.", Snackbar.LENGTH_INDEFINITE).setAction("Retry", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((MainActivity) getActivity()).loadAds();
                refreshData();
            }
        }).show();
    }
</code></pre>

<blockquote>
  <p>where</p>
</blockquote>

<pre><code>FrameLayout frameLayout = (FrameLayout) v.findViewById(R.id.fragment_latest);
</code></pre>