• ListView 自定义头部、自定义加载尾部、上拉自动加载


    1.加头尾部

    (1)定自义一个xml布局 my_headview.xml

    在Activity类里找到这个自定义布局,并添加到头部

    LinearLayout  hearderViewLayout = (LinearLayout) LayoutInflater.from(
                            xwActivity.this).inflate(R.layout.my_headview, null);

    listview.addHeaderView(hearderViewLayout);

    (2)定自义一个xml布局 my_footview.xml

    LinearLayout  footViewLayout = (LinearLayout) LayoutInflater.from(
                            xwActivity.this).inflate(R.layout.my_footview, null);

    listview.addFooterView(footerViewLayout);

    (3)注意事件

    listview一定会有Adapter,加入头尾部,必须在加入Adapter之前!

    listview.addHeaderView(hearderViewLayout);

    listview.addFooterView(footerViewLayout);

    listview.setAdapter(myAdapter);

    2.加上拉到尾部的监听件件

    listview.setOnScrollListener(new OnScrollListener() {
                public void onScrollStateChanged(AbsListView view, int scrollState) {
                    switch (scrollState) {
                    case OnScrollListener.SCROLL_STATE_IDLE: // 当不滚动时
                        // 判断滚动到底部
                        if (view.getLastVisiblePosition() == (view.getCount() - 1)) {

                           //在这里添加操作

                        }
                        break;
                    }
                }

                public void onScroll(AbsListView view, int firstVisibleItem,
                        int visibleItemCount, int totalItemCount) {

                }
            });

     

  • 相关阅读:
    不允许保存更改,阻止保存要求重新创建表的更改
    sql server导入excel等数据
    python爬虫框架(3)--Scrapy框架安装配置
    SQL server 2008安装教程
    python爬虫框架(2)--PySpider框架安装配置
    python爬虫框架(1)--框架概述
    python爬虫(8)--Xpath语法与lxml库
    FastReport Designer 应用
    BootStrap Table
    BootStrap Table
  • 原文地址:https://www.cnblogs.com/344701388xw/p/2746098.html
Copyright © 2020-2023  润新知