android-ultra-pull-to-refresh list,4.2.5 Android 下拉刷新的几个方法:SwipeRefreshLayout,android-Ultra-Pull-To-...

束向荣
2023-12-01

1: SwipeRefreshLayout

2: android-Ultra-Pull-To-Refresh(ptr),

3: PullToRefreshListView

SwipeRefreshLayout swipeRefreshLayout =(SwipeRefreshLayout)findViewById(R.id.main_swipeRefreshLayout);

// swipeRefreshLayout.setRefreshing(true);swipeRefreshLayout.setColorSchemeColors(Color.RED,Color.BLUE,Color.YELLOW);

swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);

swipeRefreshLayout.setOnRefreshListener(this);

下拉刷新的大小,只有两种模式,一个是小的,一个是大的。

swipe.setSize(SwipeRefresh.LARGE);

还可以设置一组颜色

swipe.setColorSchemeColors(Color.RED,Color.YELLOW,Color.BLUE);

swipe.setOnRefreshListener();

public ovid onRefresh(){

HttpUtils.getService().getArticle.....

就是刷新第一页。

}

/*** A simple {@linkFragment} subclass.*/public classLeiBieFragment extendsFragment implementsCallback, SwipeRefreshLayout.OnRefreshListener {

privateRecyclerView recyclerView;

privateLeiBieAdapter adapter;

privateSwipeRefreshLayout mSwipeRefreshLayout;

publicLeiBieFragment() {

// Required empty public constructor}

@OverridepublicView onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

// Inflate the layout for this fragmentView ret = inflater.from(getContext()).inflate(R.layout.fragment_lei_bie, container, false);

// return inflater.inflate(R.layout.fragment_lei_bie, container, false);mSwipeRefreshLayout=(SwipeRefreshLayout)ret.findViewById(R.id.leibie_swiperefreshlayout);

recyclerView= (RecyclerView)ret.findViewById(R.id.leibie_recyclerview);

adapter= newLeiBieAdapter(ret.getContext(),newArrayList());

recyclerView.setAdapter(adapter);

//SwipeRefreshLayout-----------

mSwipeRefreshLayout.setOnRefreshListener(this);

mSwipeRefreshLayout.setColorSchemeColors(Color.RED, Color.BLUE, Color.CYAN);

mSwipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);

//SwipeRefreshLayout----------- HttpUtils.getLeiBieService().getLeiBie(1446).enqueue(this); returnret; } //DataEntity.ReturnDataEntity.RankinglistEntity@Overridepublic voidonResponse(Call call, Response response) { adapter.addAll(response.body().getData().getReturnData().getRankinglist()); mSwipeRefreshLayout.setRefreshing(false); } @Overridepublic voidonFailure(Call call, Throwable t) { mSwipeRefreshLayout.setRefreshing(false); } @Overridepublic voidonRefresh() { HttpUtils.getLeiBieService().getLeiBie(1446).enqueue(this); }}

无论成功还是失败,都要把求收回来。

swipe.setRefreshing(false);

刷新之前一定要清空数据,并加载第一页

添加一个变量,page。

page=1;

然后

在adapter 里面添加listClean

public void clean(){

list.clean();

notify

}

在onResponse里面

page 还可以用来判断是下拉刷新和上拉加载。

if(page==1){

adapter.clear();

}

 类似资料: