I have a SwipeRefreshLayout
being used inside of Fragments that are being displayed in activities. Swiping does perform the refresh, but after I pull down it goes right back up and there's no indicator of indeterminate progress (the animated progress bars). It just disappears but still calls onRefresh() when it's done. Here's my layouts…
Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1px"
android:background="@color/drawer_background_gray"
android:clipToPadding="false"/>
</android.support.v4.widget.DrawerLayout>
Fragment 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.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"/>
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/empty_text_size"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="@color/brand_green"/>
<ProgressBar
android:id="@android:id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateOnly="true"
android:visibility="gone"
android:layout_gravity="center"/>
</FrameLayout>
Code to initialize the Fragment
's layout:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_list, null);
swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
return view;
}
There's generally a 3 to 6 second delay while refreshing, enough that it's noticeable while watching the log. It should be visible, and it worked fine when I used the now deprecated ActionBar-PullToRefresh
library. I've tried making SwipeRefreshLayout
the root view of the Fragment layout, and I tried removing the empty text and progress view, and it continues to not work.
There's a few more steps that go into my actual code that I can't reveal as it's an app being designed for my company. But it's only for providing a similar base to many different fragments that do similar things, it shouldn't affect any functionality for this.
I used this below approach and it worked for me without workarounds, even Fragments, after so many tries:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
** content **
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
AppCompat Library: com.android.support:appcompat-v7:21.0.3
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With