LayoutInflater.from(this) View.inflate()
2012-08-01 16:59
281 查看
LayoutInflater.from(this) View.inflate()
2011-12-03 21:28:57| 分类: android|字号 订阅通俗的说,inflate就相当于将一个xml中定义的布局找出来. 因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件. 因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如: View view = View.inflate(this, R.layout.dialog_layout, null); TextView dialogTV = (TextView) view.findViewById(R.id.dialog_tv); dialogTV.setText("abcd"); 如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv)肯定会报错. View.inflate()是一样的,更简单一些. |
相关文章推荐
- 自定义组合控件关于LayoutInflater.from(context).inflate(R.layout.view_title, this,true)的问题
- LayoutInflater.from(this)、inflate 详解
- LayoutInflater.from(this)的用法--inflate就相当于将一个xml中定义的布局找出来.
- LayoutInflater.from(this) 这个this是什么,加载完后的View 就是谁的。
- 源码分析初级《篇一》 为何建议使用LayoutInflater.from而不用View.inflate
- 关于LayoutInflater.from().inflate()方法不能加载自定义view的解决办法
- View.Inflate)与LayoutInflater.from().inflate();
- android程序 在View view = LayoutInflater.from(getContext()).inflate(resourceId, nul
- LayoutInflater.from(this).inflate()参数解析
- View.inflate() 和 LayoutInflater.from(context).inflate()区别
- [Android]inflate方法与 findViewById 方法区别 | LayoutInflater的inflate函数用法详解
- [Android]inflate方法与 findViewById 方法区别 | LayoutInflater的inflate函数用法详解
- Android学习笔记之LayoutInflater的inflate方法中的ViewGroup root 参数理解
- View.inflate()和LayoutInflater.inflate()的区别
- View.inflate()与LayoutInflater.inflate()的区别?
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- Android LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)的参数理解
- Android LayoutInflater.from(context).inflate
- LayoutInflater.from(this)的用法
- android中LayoutInflater.from(context).inflate的分析