inflate
来源:互联网 发布:印章制作软件 编辑:程序博客网 时间:2024/06/05 23:43
\因为在一个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)肯定会报错.
三种方式可以生成LayoutInflater:
LayoutInflater inflater=LayoutInflater.from(this);
LayoutInflater inflater=getLayoutInflater();
LayoutInflater inflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
public View inflate(intresource,ViewGrouproot,booleanattachToRoot)
在View类中,也有inflate方法
public static View inflate(Contextcontext,intresource,ViewGrouproot)
因此如果你的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)肯定会报错.
三种方式可以生成LayoutInflater:
LayoutInflater inflater=LayoutInflater.from(this);
LayoutInflater inflater=getLayoutInflater();
LayoutInflater inflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
public View inflate(intresource,ViewGrouproot,booleanattachToRoot)
在View类中,也有inflate方法
public static View inflate(Contextcontext,intresource,ViewGrouproot)
- inflate
- inflate
- inflate
- inflate
- inflate
- Inflate
- inflate
- Inflate
- Android:inflate.inflate()方法
- RelativeLayout && inflate
- getLayoutInflater().inflate
- USACO inflate
- Android Inflate
- inflate用法
- inflate理解
- LayoutInflater inflate()
- inflate 初识
- inflate方法
- android WIFI 流程
- 2011.7.18 许志平老师课上主要内容
- JavaScript简介
- Understanding Disk I/O - when should you be worried?
- EJB是什么呢?
- inflate
- try{jsp url传参}
- Windows环境下libxml2库的使用小结
- Source Insight获取当前编辑的文件名并拷贝至剪切板
- android EditText 属性介绍
- 在HTML中使用JavaScript
- 貌似有機會
- Windows 编程知识要点总结1 - Windows位图知识
- ROS智能集体、单IP限速脚本2.9.27