zoukankan      html  css  js  c++  java
  • 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);

    解决问题!

  • 相关阅读:
    基于python的种子搜索网站(三)项目部署
    Python 的 Geth 封装库 PyGeth
    主题: 002.04 Tkinter 星空大战
    python 打飞机项目 (实战一)
    python使用mysql的一些坑
    Python 变量与运算符
    字符流
    IO字节流(2)
    端口转发
    IO流(1)
  • 原文地址:https://www.cnblogs.com/andlp/p/5045947.html
Copyright © 2011-2022 走看看