SwipeRefreshLayout trigger programmatically

前端 未结 7 2098
独厮守ぢ
独厮守ぢ 2020-12-04 16:40

Is there any way to trigger the SwipeRefreshLayout programmatically? The animation should start and the onRefresh method from the OnRefreshLi

相关标签:
7条回答
  • 2020-12-04 16:59

    Simply create a SwipeRefreshLayout.OnRefreshListener and call its function onRefresh() whenever needed:

    SwipeRefreshLayout srl;
    SwipeRefreshLayout.OnRefreshListener refreshListener;
    
    srl = (SwipeRefreshLayout)v.findViewById(R.id.swipeRefreshLayout);
    
    refreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
          //Do your stuff here
        }
    };
    srl.setOnRefreshListener(refreshListener);
    

    Now, whenever you want to call it manually, just call it through the listener

    refreshListener.onRefresh();
    
    0 讨论(0)
提交回复
热议问题