Android - SwipeRefreshLayout with empty textview

后端 未结 15 1420
悲哀的现实
悲哀的现实 2020-12-05 02:06

I\'ve implemented SwipeRefreshLayout into my app but it can only hold one direct child which should be the listview. I\'m trying to figure out how to add an emp

15条回答
  •  天命终不由人
    2020-12-05 03:05

    There is no need for any workaround.

    You can simply use this view hierarchy :

        
    
            
    
                
            
    
            
        
    

    Then, in code, you just call:

    _listView.setEmptyView(findViewById(android.R.id.empty));
    

    That's it.


    EDIT: If you wish to be able to swipe-to-refresh even when the empty view is shown, you will have to somehow avoid hiding the ListView, so you could use a customized ListView that has this function inside:

    @Override
      public void setVisibility(final int visibility)
        {
        if(visibility!=View.GONE||getCount()!=0)
          super.setVisibility(visibility);
        }
    

    Together with the solution I wrote, the swipe-to-refresh is shown no matter how many items you are showing.

    Of course, if you really want to hide the ListView, you should change the code. Maybe add "setVisibilityForReal(...)" :)

提交回复
热议问题