<com.handmark.pulltorefresh.library.PullToRefreshExpandableListView android:id="@+id/expand_list" android:layout_width="match_parent" android:layout_height="match_parent" />2. 在你的Activity代码中进行简单的设置:
mExpandList = (PullToRefreshExpandableListView) rootView.findViewById(R.id.expand_list); mExpandList.getRefreshableView().setGroupIndicator(null); mExpandList.getRefreshableView().setDivider(null); mExpandList.getRefreshableView().setSelector(android.R.color.transparent); mExpandList.getRefreshableView().setOnGroupClickListener(this); mExpandList.setOnRefreshListener(this);第一行是找到这个View,最后一行是为它加上刷新的监听器,中间的几行是我对ExpandableListView进行一些设置。
@Override public void onRefresh(PullToRefreshBase<ExpandableListView> refreshView) { if (!isRefreshing) { isRefreshing = true; updateList(true); } else { mExpandList.onRefreshComplete(); } }一般来说我们会开另一个线程去获取数据,所以这儿会加上一个判断,如果已经在获取数据了,就onRefreshComplete(),就是将下拉收起;否则就去开新线程取数据,取完记得也要onRefreshComplete()哦!// set mode to BOTH mExpandList.setMode(Mode.BOTH); mExpandList.getLoadingLayoutProxy(false, true).setPullLabel(getString(R.string.pull_to_load)); mExpandList.getLoadingLayoutProxy(false, true).setRefreshingLabel(getString(R.string.loading)); mExpandList.getLoadingLayoutProxy(false, true).setReleaseLabel(getString(R.string.release_to_load));Mode设置为Mode.BOTH后,下拉和上拉都会执行onRefresh()中的方法了。
public boolean isHeaderShown() { return getHeaderLayout().isShown(); } public boolean isFooterShown() { return getFooterLayout().isShown(); } 这样就行了哦,重新编译一下这个工程,和你自己的工程。@Override public void onRefresh(PullToRefreshBase<ExpandableListView> refreshView) { if (!isRefreshing) { isRefreshing = true; if (mExpandList.isHeaderShown()) { Utils.LOGD("pull-to-refresh"); refreshOnlineStatus(true); } else if (mExpandList.isFooterShown()) { Utils.LOGD("pull-to-load-more"); loadNextPage(); } } else { mExpandList.onRefreshComplete(); } } 很简单吧,这样我们就YD地使用PullToRefresh实现了下拉刷新和上拉加载,LOL,希望多多少少能帮到大家。
以上所述是小编给大家介绍的使用PullToRefresh实现下拉刷新和上拉加载,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!