奇怪的代码
来源:互联网 发布:响应式网站 知乎 编辑:程序博客网 时间:2024/05/17 02:59
TextView title = null;
TextView text = null;
// if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item, null);
title =(TextView) convertView.findViewById(R.id.title);
text= (TextView) convertView.findViewById(R.id.content);
// }
title.setText("title");
TextView text = null;
// if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item, null);
title =(TextView) convertView.findViewById(R.id.title);
text= (TextView) convertView.findViewById(R.id.content);
// }
title.setText("title");
text.setText("content");
这代码写的是有问题的,不是我写的。因为!convertview==null后text,title就空指针了
不过要说的问题不是这个,用这代码列出五个列表的时候,五个列表都没有超出屏幕,根据网络资料来说convertView是绝对== null,也就是
title =(TextView) convertView.findViewById(R.id.title);
text= (TextView) convertView.findViewById(R.id.content);
是必然会运行的,也就是说title 是不会空指针的,但是,实际运行却错误,之后,我其他地方什么都没改,将convertview判空操作就给注释掉了,也就是上面的代码,之后就没有错误了,
两者唯一的区别就是 title.与text能不能得到实例,也就是 convertView = LayoutInflater.from(mContext).inflate(R.layout.item, null);
title =(TextView) convertView.findViewById(R.id.title);
text= (TextView) convertView.findViewById(R.id.content);有没有执行,也就是convertView == null是不是真的成立!也就是说,即使没有超出屏幕,也可能不为null?
0 0
- 一段奇怪的代码
- 奇怪的代码
- 一段奇怪的代码:
- c#很奇怪的代码
- 一段奇怪的HTML代码
- 奇怪的C语言代码
- asio中奇怪的代码
- 奇怪代码
- 关于这段奇怪代码的解释
- 代码中出现的奇怪问题原因
- 密码学_一段奇怪的代码
- wcf的svcutil.exe工具生成代码的奇怪问题
- 编写安全代码:避免奇怪的逻辑引发的bug
- 晕了,C#莫名其妙的写出来一个奇怪代码。。。。。。
- 一段关于C内存分配的奇怪代码
- 奇怪,奇妙,反正是不想看到的代码
- Rtems中一段代码执行后的奇怪现象
- 奇怪的浏览器显示问题,代码正确很重要啊。
- 均值不等式及其多维形式
- BZOJ 3624 并查集 (Kruskal)
- windows系统下安装Java的JDK详细流程
- 【笔记】用路由器虚拟借口配置Vlan间的通信
- 网卡故障:弹出界面eth0: 错误
- 奇怪的代码
- PAT1061. 判断题(15)
- 进制转换
- 3DES
- [OI]Tarjin算法整理
- 1036. Boys vs Girls (25)
- win7系统安装
- DES
- 深入GetMessage,PeekMessage以及Windows消息机制