Inflater与findViewById()区别
来源:互联网 发布:淘宝商城女装朵以 编辑:程序博客网 时间:2024/04/30 08:01
想给listview添加个表头,addHeaderView(findViewById(R.layout.listview_head))运行后崩掉了,跑了个NullPointerException出来,问LZ,曰:findviewbyid返回的界面控件视图,不是返回布局视图 。于是new了个textview add进去,一切正常。百度了一下发现下面这个东东,哦原来如此!(不知道怎么搞的,文字打到插入代码里了)
/** * Inflater英文意思是膨胀,在Android中应该是扩展的意思吧。 LayoutInflater的作用类似于 * findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化! 而 * findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。 */ // LayoutInflater的作用是,把一个View的对象与XML布局文件关联并实例化 LayoutInflater inflater = (LayoutInflater) listviewActivity.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // LayoutInflater的作用是,把一个View的对象与XML布局文件关联并实例化 View itemView = inflater.inflate(R.layout.listview_item, null); // View的对象实例化之后,可以通过findViewById()查找布局文件中的指定Id的组件 TextView title = (TextView) itemView.findViewById(R.id.txttitle); TextView text = (TextView) itemView.findViewById(R.id.txtContent);
FROM:http://www.cnblogs.com/yourancao520/archive/2012/04/06/2434745.html
0 0
- Inflater与findViewById()区别
- Inflater与findViewById()区别
- Inflater与findViewById()区别
- [Android] setContentView和inflater区别以及findViewById和inflater的区别
- Android] setContentView和inflater区别以及findViewById和inflater的区别
- Inflater方法和findViewById()
- layoutinflater 与 findviewbyid区别
- Inflater—— LayoutInflater和findViewById()
- Android inflate方法与 findViewById 方法区别
- Android LayoutInflater详解 与 findViewById() 的区别
- inflate方法与findViewById的区别
- inflate方法与findViewById的区别
- inflate 方法与 findViewById方法的区别
- view.inflater和inflater.inflater有什么区别
- 有关Fragment的getActivity().findViewById,以及inflate与 findViewById 区别、setContentView和inflate的区别!!!
- inflate, findViewById与setContentView的区别与联系
- inflate, findViewById与setContentView的区别与联系
- inflate, findViewById与setContentView的区别与联系
- springSecurity源码分析——DelegatingFilterProxy类的作用
- Mybatis学习- 拦截器-实现分页
- xmpp Use of undeclared identifier 'ddLogLevel'
- Visa将为基于云的安全移动支付提供支持
- iOS 自定义UITabbar边框问题
- Inflater与findViewById()区别
- 《Oracle 网络配置 本人最感兴趣的章节之一》
- JAVA大数阶乘
- Cocos2d-x 3.0 中文基础教程-精灵帧缓存(SpriteFrameCache)
- 124暖暖简欧风
- 类unix的路径小记
- hadoop面试题答案
- object to xml
- linux中c语言errno的使用