inflate() 和 findViewById
来源:互联网 发布:泡泡堂单机版mac 编辑:程序博客网 时间:2024/05/16 03:24
今天使用CursorAdapter,在newView()中使用LayoutInflater.inflate() 填充一个View, 然后使用findViewById,想设置View的内容,
结果 findViewById(R.id.pb) 返回的是null..., 而且仅仅第一个findViewById(R.id.pb)返回null,
不解,于是找到了下面一段文字,豁然.
原来我还不能正确使用findViewById().
以下内容为转载:
转自:http://blog.csdn.net/tanjunjie621/article/details/7334503
1.findViewById()是View对象的方法,先通过inflate()方法得到View,调用这个View对象的getViewById()方法,就能得到这个View树上的子View。
2.inflate()函数可以通过getSystemService()方法得到,参数是LAYOUT_INFLATER_SERVICE。
3.inflate()函数的第一个参数是布局文件的R引用,第二个参数是根 ViewGroup,也就是从哪个ViewGroup节点开始渲染。对于第二个参数,需要实例化这个VIewGroup,可以这么做,在XML布局文件中设置这个root的id,然后用findViewById()方法通过id就能得到它,比如
View layout = inflater.inflate(R.layout.toast_layout,(ViewGroup) findViewById(R.id.toast_layout_root));
谢过.
- inflate和findViewById
- inflate() 和 findViewById
- inflate()和findViewById()
- inflate和findViewById方法对比
- inflate()和findViewById()函数的用法
- setContentView和inflate调用findViewById的区别
- findViewById()与Inflate()和setContentView()关系扯谈
- setContentView、findViewById 和 inflate 的区别?
- findViewById()与Inflate()和setContentView()关系扯谈
- setContentView、findViewById 和 inflate 的区别?
- findViewById的问题和inflate(0方法
- 有关Fragment的getActivity().findViewById,以及inflate与 findViewById 区别、setContentView和inflate的区别!!!
- inflate与findViewById
- android 中findViewById和inflate的使用区别
- Android中setContentView、addContentView、inflate、LayoutInflater和findViewById()区别
- 关于android之LayoutInflater的inflate()方法和findViewById()方法
- Android inflate方法与 findViewById 方法区别
- inflate与setcontentview及findviewbyid(一)
- Error和Exception的区别
- 程序员技术面试的福音:包你通过技术面试。
- cocos2dx3.0 自动绑定自定义的C++到lua
- 关于Cocos2d-x2.1.x与CocosBuilder3.0a 的自动资源目录摆放
- Java中BigDecimal的8种舍入模式
- inflate() 和 findViewById
- photoshop--抽出滤镜
- 获取存储过程内容
- 561456
- 阴天不下雨
- 复盘:红米成功背后,雷军的五个艰难决定
- MMA7260三轴加速度计
- 获取iPhone设备的IP的地址
- C语言有符号整数隐式转换无符号整数出现的陷阱