When entering activity, a new stream is triggered with loading and the loading indicator is not visible until the adapter of the ListView empty. When updating everything is displayed correctly. Enable and disable animation occurs in the onPreExecute() and onPostExecute() methods, respectively.

  @Override protected void onPreExecute() { super.onPreExecute(); ... SwipeRefreshLayout SRL = (SwipeRefreshLayout)findViewById(R.id.srl); SRL.setRefreshing(true); ... } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); ... SwipeRefreshLayout SRL = (SwipeRefreshLayout)findViewById(R.id.srl); SRL.setRefreshing(false); ... } 

    2 answers 2

    SwipeRefreshLayout wildly buggy and regularly broken by Google in updates to support libraries. Over the years, it was not possible to find a normal solution to this problem. As a temporary crutch, you can offer only a delayed execution of the setRefreshing method in another thread like this:

     //workaround from //http://stackoverflow.com/a/26910973/3212712 swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(isLoading); } }); 

    At the same time, if you leave with the activation / close the fragment before the circle is canceled (the Internet is slow, the user is tired of waiting), then it may not disappear at all from the screen, since was added to it by another thread.

    So, perhaps, you need to completely abandon the manual call of the circle and replace it with your implementation of the load indicator, leaving the circle only to be able to "pull to update"

    • SRL was added to suport.v4 from version 19.1.0 of March 2014 and has since been fixed only once in the audit of suport.v4 20.0 in July of the same year, so what about long years and regular rework you got a little hot yet :) . As for the glitch I will not say, I did not have to use it - pavlofff
    • @pavlofff, I did not check what and when it was fixed there, but it definitely broke in some version up to 21.1.1 and then in version 23.2.0. Here, I even wrote about it: ru.stackoverflow.com/a/497162/17609 - Yuriy Spb
    • Well, yes - yes, I sometimes happen to be overly categorical - I lost a lot of blood to this widget at one time) - YuriySPb

    Solved the problem a kind of data caching. When you open the Activity parses and fills the adapter from the cache. After that, a stream is already being executed for downloading (updating) data, in which everything is already displayed as it should.

    UPD

    The problem does not occur if you do not use listView.setAdapter(null); , and transfer the adapter with an empty data array. This also applies to RecyclerView .

    • one
      And if this is the first launch and there is no cache, or was it manually deleted by the user? - Yuriy SPb
    • one
      I also thought about this, I decided not to display anything on the first boot. But these are small sacrifices for "big success." - zTrap