今天调试的时候,才知道。

原来listview 的 getChildCount 取得是当前可先的list item 的个数,而不是整个listview 的count.

整个listview 的数量应该是 getCount

/**
* @return The number of items owned by the Adapter associated with this
* AdapterView. (This is the number of data items, which may be
* larger than the number of visible views.)
*/
@ViewDebug.CapturedViewProperty
public int getCount() {
return mItemCount;
}

getChildCount

/**
* Returns the number of children in the group.
*
* @return a positive integer representing the number of children in
* the group
*/
public int getChildCount() {
return mChildrenCount;
} /**
* Returns the view at the specified position in the group.
*
* @param index the position at which to get the view from
* @return the view at the specified position or null if the position
* does not exist within the group
*/
public View getChildAt(int index) {
if (index < 0 || index >= mChildrenCount) {
return null;
}
return mChildren[index];
}

总结:

getChildCount 和 getChildAt 都是取得listView当前可见的item.

ListView getChildCount 以及getChildAt 坑 误区指南的更多相关文章

  1. Android中ListView.getCount()与ListView.getChildCount()区别和OnScrollListener()各个参数的区别

    istView.getCount()(实际上是 AdapterView.getCount()) 返回的是其 Adapter.getCount() 返回的值.也就是“所包含的 Item 总个数”. Li ...

  2. ListView.getChildCount() 详解

    ListView.getCount() 返回的所包含的item总个数 ListView.getChildCount() (ViewGroup.getChildCount()) 返回的是现实层面上所包含 ...

  3. 【干货】基于镜像部署的Gitlab-CI/CD实践和坑位指南

    引言 看过前文的博友可能注意到我是把 部署dll文件拷贝到生产机器,之后在生产机器上使用docker-compose即时创建镜像, 并没有完成CI/CD, 只是在原来传统部署方式下 将部署文件容器化. ...

  4. Android中GridView、ListView 的 getChildAt() 方法返回null 问题

    开发的Android app用到了GridView或者ListView,通常使用getChildAt(int position)方法获取当前点击或者选中的View(即position对应的View). ...

  5. 两listview联动

    package com.mttz; import java.util.ArrayList;import java.util.List; import com.mttz.adapter.CaiDanAD ...

  6. ListView只更新某个item

    方案1:针对需要更新的item调用public View getView(int position, View convertView, ViewGroup parent)即可.如: public c ...

  7. Android使用ListView应该注意的地方

    在ListView中设置Selector为null会报空指针? mListView.setSelector(null);//空指针 试试下面这种: mListView.setSelector(new ...

  8. ListView实现原理

    转载:http://blog.csdn.net/guolin_blog/article/details/44996879 在Android所有常用的原生控件当中,用法最复杂的应该就是ListView了 ...

  9. Android ListView OnItemLongClick和OnItemClick事件内部细节分享以及几个比较特别的属性

    本文转自 http://blog.sina.com.cn/s/blog_783ede030101bnm4.html 作者kiven 辞职3,4个月在家休息,本以为楼主要程序员逆袭,结果失败告终继续码农 ...

随机推荐

  1. 新版mysql 5.7的group_by非常不和谐

    sqlalchemy.exc.OperationalError OperationalError: (_mysql_exceptions.OperationalError) (1055, " ...

  2. 什么是DTO?

    DTO: Data Transfer Object Wikipedia定义:Data transfer object (DTO)[1][2] is an object that carries dat ...

  3. tomcat7 的The Apache Tomcat Native library which allows optimal performance 的解决

    1.        用Myeclipse启动tomcat7启动时可能会收到下面的信息: 七月 24, 2014 10:13:30 上午 org.apache.catalina.core.AprLife ...

  4. js中关于假值和空数组的总结

    先上x==y运算符的算法细节: 如果x不是正常值(比如抛出一个错误),中断执行. 如果y不是正常值,中断执行. 如果Type(x)与Type(y)相同,执行严格相等运算x === y. 如果x是nul ...

  5. rabbitmq安装使用

    使用 http://www.open-open.com/lib/view/open1325131828249.html ubuntu:apt-get install erlang-noxsudo ap ...

  6. ADO.NET 之断开连接层

    定义: 使用ADO.NET断开连接层,就会使用System.Data命名空间的许多成员(主要是DataTable.DataTable.DataRow.DataColumn.DataView和DataR ...

  7. jQuery 二级联动

    jQuery 二级联动 ----请选择省份---- 北京 上海 江苏 ----请选择城市---- 东城 西城 崇文 宣武 朝阳  黄浦 卢湾 徐汇 长宁 静安 南京  镇江 苏州 南通 扬州 & ...

  8. computed--实时计算属性

    项目:https://github.com/ccyinghua/vue-node-mongodb-project/blob/master/07-shoppingCart.md 实时计算属性的compu ...

  9. 利用Kettle转储接口数据

    1.     项目背景 1.1.  项目背景 数据接口 API:应用程序接口(Application Program Interface)的简称,是实现计算机软件之间数据通信的工具.同时API也是一种 ...

  10. int ,long long 范围

    类型名称 字节数 取值范围signed char 1 -128-+127short int 2 -32768-+32767int 4 -2147483648-+2147483647(10位数 2^31 ...