1

I have activity that contain viewpager with tabhost like below

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/white"
            app:tabMode="fixed"
            app:tabTextAppearance="@style/MyTextAppearance" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

and it contain 3 fragments,each fragment contain recyclerview inside swiperefreshlayout like this,

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_action1" />

        <SwipeRefreshLayout
            android:id="@+id/swipeRefreshLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical" />
        </SwipeRefreshLayout>

</android.support.design.widget.CoordinatorLayout>

but it not call swipeRefreshLayout.setOnRefreshListener.... any thing wrong please help me.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rgv
  • 504
  • 5
  • 23

2 Answers2

0

You are missing android.support.v7.widget in RecyclerView and android.support.v4.widget in SwipeRefreshLayout

Use this inside your fragment

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.v4.widget.SwipeRefreshLayout>

Inside your fragment initialize SwipeRefreshLayout and call OnRefreshListener

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
       @Override
       public void onRefresh() {
           //Peform any task
       }
});
akhilesh0707
  • 6,709
  • 5
  • 44
  • 51
0

Always keep your layout xml like below code mentioned

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/videoPhotoRecycler"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="never" />

        </LinearLayout>
    </android.support.v4.widget.SwipeRefreshLayout>

You must use one ViewGroup Layout like LinearLayout / RelativeLayout / FrameLayout as parent in SwipeRefreshLayout.

I hope its works.

Feel free to revert if still the issue is not solved.