Android - SwipeRefreshLayout with empty textview

后端 未结 15 1434
悲哀的现实
悲哀的现实 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:00

    Probably late, But if you're still facing this issue, Here is the clean solution! There is no need of creating another SwipeRefreshLayout.

    wrap empty view into a ScrollView. Stick both AdapterView and the ScrollView into a ViewGroup and put it into the SwipeRefreshLayout

    Sample:

    
    
        
    
            
    
            
    
                
    
            
    
        
    
    
    

    EDIT

    Here is much more simpler way.

    check if your list is empthy. if yes then make it invisible. Sample:

    if(lst.size() > 0) {
     mRecyclerView.setVisibility(View.VISIBLE);
    //set adapter
    }else
    {
      mRecyclerView.setVisibility(View.INVISIBLE);
     findViewById(R.id.txtNodata).setVisibility(View.VISIBLE);
    }
    

    this will make mRecyclerView still there and all swipes will be working fine now even there is no data!

提交回复
热议问题