pulltorefresh滚动到底部

如果用ListView,让它滚动到顶部,一般是这样写的:

 

if (!listView.isStackFromBottom()) {
	listView.setStackFromBottom(true);
}
listView.setStackFromBottom(false);


但是,使用PullToRefreshListView以后,发现该对象竟然没有setStackFromBottom()方法!

 

翻翻它的源码,发现是这样的:

 

public class PullToRefreshListView extends PullToRefreshAdapterViewBase<ListView>{...}

它并不是继承于ListView,所以也无法将这个对象cast到ListView。

 

但是,实际上PullToRefreshListView的主体确实是一个ListView,那么如何使用属于ListView的方法呢?

在百度、谷歌搜索了半天,终于在stackoverflow上找到了答案:Retaining scroll position on Pull To Refresh

PullToRefresh为了实现各种不同的View的下拉刷新,并不是简单的继承自ListView,而是采用了泛型。

实际上可以理解为在ListView(或者其他想要实现下拉刷新的View)外面包了一层ParentView

想要得到里面的ListView,有这样一个方法:

 

listView.getRefreshableView();

因此,想要让它回到顶部,代码如下:

 

 

ListView mlist = listView.getRefreshableView();
if (!(mlist).isStackFromBottom()) {
	mlist.setStackFromBottom(true);
}
mlist.setStackFromBottom(false);

 

 

解决问题!

posted @ 2015-12-14 17:44  andlp  阅读(508)  评论(0编辑  收藏  举报