2

I have implemented a SwipeRefreshLayout on my ListView, and it is working, but not how I want it to.

First of all, the refresh triggers before I lift my finger, which doesn't feel right because it moves the content back to the top even though my finger is still sitting in swiped down position. Also the distance to trigger is really short and setDistanceToTriggerSync from the docs is not available to me for some reason.

second, I'd like some sort of view the be displayed in the gap when my list view is pulled down, like a text that tells the user "swipe down to refresh" or a an animation (like the dancing ghost in snap chat). How do I set this View

Here's what I have

<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dashboardRootLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

>

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lvDashboard"
        android:background="#ffffff"
        />
Siavash
  • 7,583
  • 13
  • 49
  • 69

1 Answers1

1

Why isn't the setDistanceToTriggerSync available?

Anyway the default behavior of the SwipeRefreshLayout does not have that extra view, it just has a special progress bar and a listener for refreshing and showing or not the progress of refresh. Also it can change the look of the actionbar with the refresh message.

Possible solution:

If you want that special view, of the top of my head I can think of having the list being moved down with animation and creating or putting VISIBLE the view you want to show on the top of the SwipeRefreshLayout.

    SwipeRefreshLayout swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.dashboardRootLayout);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener()
      {
        @Override
        public void onRefresh()
          {
          // do animation
          // set the view you want to show VISIBLE
          }
      });

You could actually implement all of this by yourself without the SwipeRefreshLayout since you don't want the default behavior. }

mthandr
  • 3,062
  • 2
  • 23
  • 33
  • thank you @tiago, But my biggest concern is the fact that the list refreshes before I lift my finger from the screen. – Siavash Dec 30 '14 at 00:42
  • also, I dont know why setDistanceToTriggerSync is not available. it exists in the API documentation, but in my code, the method does not exist. It's as if google took it out, but for got to update the documentation, or vice versa. But it will not show up with autoComplete, and if I manually type it in, I get a symbol not resolved error. I looked at the source code for SwipeRefreshLayout and the method is not there. The package is android.support.v4.widget. – Siavash Dec 30 '14 at 00:51
  • Look at this then: http://stackoverflow.com/questions/22856754/how-to-adjust-the-swipe-down-distance-in-swiperefreshlayout There are no public methods to change the distance trigger, so you have to do that is explained in the accepted answer. – mthandr Dec 30 '14 at 01:25
  • and the pull to refresh normally works like that. You pull something to the limit and it begins to move. Because the distance is low for the device you are using, maybe, it feels too much fast. Then increase the distance to refresh and it should feel better. – mthandr Dec 30 '14 at 01:29