android使用SwipeRefreshLayout实现下拉刷新

SwipeRefreshLayout可以包裹一些组件,比如recyclerview,listview,webview等,实现下拉刷新,上拉加载,实例:

  • 布局文件:
      
  • activity中,主要是设置刷新监听,刷新结束时,调用setRefreshing(false);隐藏刷新进度条
public class WaterfallActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {

    private SwipeRefreshLayout mSwipeRefreshWidget; 
   @Override
  protected void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);   
        ......        
        mSwipeRefreshWidget = (SwipeRefreshLayout)  findViewById(R.id.swipe_refresh_widget);    
        mSwipeRefreshWidget.setOnRefreshListener(this);    
}

    private static final int REFRESH_COMPLETE = 0X110;   private Handler mHandler = new Handler()
    {
        public void handleMessage(android.os.Message msg)
        {
            switch (msg.what)
            {
                case REFRESH_COMPLETE:
                    mSwipeRefreshWidget.setRefreshing(false);
                   break;    
}
        };
  };    
@Override
  public void onRefresh() {
        mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);
  }

}

你可能感兴趣的:(android使用SwipeRefreshLayout实现下拉刷新)