simple example on how to use SwipeRefreshLayout with ListView

17,580

Solution 1

Call the method setRefreshing(false)

http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#setRefreshing(boolean)

Solution 2

Or you could just use this beautiful gist here.

Gist - https://gist.github.com/antoniolg/9837398

Blog - http://antonioleiva.com/swiperefreshlayout/

Share:
17,580
Katedral Pillon
Author by

Katedral Pillon

Updated on June 12, 2022

Comments

  • Katedral Pillon
    Katedral Pillon almost 2 years

    Does anyone have a simple example on how to use SwipeRefreshLayout with a ListView? Here is my situation:

    I have a class SynchDogs that pulls data from the server. So that class serves as the source for my adapter. I want to use SwipeRefreshLayout for refreshing the adapter and so the ListView. DogActivity is an Observer of SynchDogs so that DogActivity implements an update method that is called when new data is ready.

    So I implement onRefresh as

    @Override
    public void onRefresh() {
        SynchDogs.getInstance().synchronizeWithServer();
    }
    

    So I am supposing this is all I need to initiate the start of pull-to-refresh. If so, inside update what do I do to end the call?

    I also already have

    swipeLayout = (SwipeRefreshLayout) 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);
    

    update

    Basically, I want to know the call for stopping the color show.

  • Katedral Pillon
    Katedral Pillon about 10 years
    Then maybe there is something else wrong with my code because I did that.
  • Katedral Pillon
    Katedral Pillon about 10 years
    All I have to do is swipeLayout.setRefreshing(false) right?
  • Katedral Pillon
    Katedral Pillon about 10 years
    Yep, I had a bug somewhere else.
  • mipreamble
    mipreamble about 10 years
    @AlvaroSantisteban : Thank you. Added the blog to the answer.
  • Andras K
    Andras K about 10 years
    this tutorial can also be helpful: howrobotswork.wordpress.com/2014/04/13/…
  • Harshvardhan Trivedi
    Harshvardhan Trivedi over 9 years
    i think this link might help,survivingwithandroid.com/2014/05/…