得到inflater的两种方法
来源:互联网 发布:雷霆战机网络连接超时 编辑:程序博客网 时间:2024/04/29 06:22
Inflater英文意思是膨胀,在Android中应该是扩展的意思吧。
LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。
(0)她可以有很多地方可以使用,如BaseAdapter的getView中,自定义Dialog中取得view中的组件widget等等。
LayoutInflater inflater = LayoutInflater.from(this);
View view=inflater.inflate(R.layout.ID, null);
或者干脆并成一句:
View view=LayoutInflater.from(this).inflate(R.layout.ID, null);
另一种方法:
view plaincopy to clipboardprint?
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.ID, null);
上面2种方法本质上是一样的,看下面的源码,form()调用的就是getSystemService():
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}
LayoutInflater的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout文件夹下的xml布局文件,并且实例化!而 findViewById()是找具体某一个xml下的具体 widget控件(如:Button,TextView等)。
(0)她可以有很多地方可以使用,如BaseAdapter的getView中,自定义Dialog中取得view中的组件widget等等。
它的用法有2种:
第一种:
View layout = inflater.inflate(R.layout.main, null);
第二种:
view plaincopy to clipboardprint?LayoutInflater inflater = LayoutInflater.from(this);
View view=inflater.inflate(R.layout.ID, null);
或者干脆并成一句:
View view=LayoutInflater.from(this).inflate(R.layout.ID, null);
另一种方法:
view plaincopy to clipboardprint?
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.ID, null);
上面2种方法本质上是一样的,看下面的源码,form()调用的就是getSystemService():
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}
0 0
- 得到inflater的两种方法
- 得到swf路径的两种方法
- 得到屏幕大小的两种方法
- 得到LAYOUTInflater的两种方法
- inflater.inflate()方法的理解
- 获取inflater的多种方法
- 两种方法得到上次插入数据的ID
- Js得到radiobuttonlist选中值的两种方法
- jsp中得到ContextPath的两种方法
- Js得到radiobuttonlist选中值的两种方法
- GCC得到系统时间的两种方法
- 得到一个String类型的首位两种方法
- jsp中得到ContextPath的两种方法
- 【android】LayoutInflater 的 inflater 方法浅析
- 得到当前系统的转储文件的两种方法
- 获取inflater 的三种方式
- inflater的三种加载方式
- NetBeans IDE VWP 数据表中当前行的两种得到方法
- jQuery 弹出层
- 2. Add Two Numbers
- AlertDialog 提示框 | ProgressDialog 进度对话框
- UVA-299 Train Swapping
- 索引优化MAX()
- 得到inflater的两种方法
- 智能终端语音加解密
- 《Testing with Xcode》第一章——QuickStart
- rom 机
- 机器学习算法思想简单梳理
- 64位win中用PLSQL Developer连接64位Oracle数据库
- UVA-10106 Product
- (4)
- trigger和triggerHander的区别