Android中GridView、ListView 的 getChildAt() 方法返回null 解决方案
来源:互联网 发布:淘宝会员号是什么 编辑:程序博客网 时间:2024/05/22 12:00
最近测试出了一个bug,就是listView里面加载第一页数据时在listView的click事件中获取list中Item的某个子控件时无异常,但是如果一旦进行滑动到下页显示的item复用第一页的item时再获取获取list中Item的某个子控件时出现空指针异常,可以看我打断点调试的数据
position为0获取没有异常
position为6复用了第一页的view
也就是说getChildAt(int position)方法中的position指的是当前可见的第几个元素,并不是在listview中的position位置,既然知道了问题那解决也就有方案了,如果要获取当前可见的第几个元素,那么拿到当前的位置减去第一个可见的view的位置不就行了吗?
于是把原来的position改一下:
TextView order = (TextView) lv.getChildAt(position).findViewById(R.id.order_number);
再次进行断点调试:
阅读全文
0 0
- Android中GridView、ListView 的 getChildAt() 方法返回null 解决方案
- Android中GridView、ListView的getChildAt方法返回null
- 【转】Android中GridView、ListView的getChildAt方法返回null
- Android中GridView、ListView的getChildAt方法返回null
- 解决Android中GridView、ListView的getChildAt方法返回null的问题
- Android ListView、GridView中getChildAt返回值不正确的问题
- Android 中Listview方法getChildAt()返回为空的问题
- Android中ListView和GridView通过getChildAt方法得到相应的Item并刷新
- ListView自定义后,在onItemClick中getChildAt返回null问题
- ListView自定义后,在onItemClick中getChildAt返回null问题
- ListView自定义后,在onItemClick中getChildAt返回null问题
- listview的getChildAt方法
- 关于Listview的getChildAt方法返回空值的解决办法
- Listview 中 getChildAt方法记录
- Android ListView.getChildAt(index)==null
- 关于Listview的getChildAt方法
- ListView的getChildAt(i)方法
- 【android】ListView中getChildAt(index)的真正含义
- Reclyclerview 的条目的textview展开,收起
- PAT 1029旧键盘
- leetcode -- 557. Reverse Words in a String III 【字符反转 + 字符数组 + 双指针 + 状态记录】
- Unity开关门的脚本,从VRTK的例子里边找的
- UESTC 1131 男神的礼物
- Android中GridView、ListView 的 getChildAt() 方法返回null 解决方案
- 字符串去重
- 记录小错误
- FTP内部常用命令
- 经常用到的字符串截取
- thymeleaf快速入门教程
- 多线程编程之二——MFC中的多线程开发
- mysql sum 统计字段数值类型是double出现精度失真问题
- 集成阿里热修复找不到so的问题