Inflater与findViewById()区别
/**
* 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);
/**
* 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);
Inflater与findViewById()区别的更多相关文章
- View.findViewById()和Activity.findViewById()区别
在网上看见View.findViewById() 和 Activity.findViewById()执行效率不一样 使用Activity.findViewById()如: TextView tv_in ...
- 关于在findViewById()方法时遇到的一些问题
最近需要做一个关于色卡的App,需要用到LayoutInflater来实现标签动态切换View界面,但是发现在使用过程中App突然会闪退, 闪退目前已解决. 先看下关于findViewById()的详 ...
- 6、Android之LayoutInflater.inflate()
LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个 ...
- android LayoutInflater.inflate()的参数介绍
LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个 ...
- ListView优化-ViewHolder缓存
安卓开发中ListView控件是一个使用频率相当的高级控件,通常用于展示一系列相似度极高的数据,当数据量极大或布局相当复杂时,ListView的性能优化就显得非常重要.所以在开发中不但功能上要满足,而 ...
- inflate方法与findViewById的区别
LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来找 re ...
- inflate, findViewById与setContentView的区别与联系
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...
- inflate, findViewById与setContentView的区别与联系 分类: H1_ANDROID 2014-04-18 22:54 1119人阅读 评论(0) 收藏
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...
- android获取inflater
LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 获取LayoutInflater的方法有如下三种: ? LayoutInflater inflater=(La ...
随机推荐
- 解决spring-boot-starter-logging与log4j冲突
由于公司在super-bom里配置了检查规则,build项目时遇到错误: [ERROR] [XXX Enforcer Rules] find DuplicateClasses Found in:org ...
- AJAX 实时读取输入文本(php)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Oracle 12c安装详细步骤,带截图
1,在官网上下载oracle的压缩文件,两个都要下载. 并两个同时选中解压在一个文件夹里面. 2,解压之后,如下图,点击setup.exe稍等一会儿 ,3,开始安装: 不选点击下一步,或者直接点击下一 ...
- 与其他Javascript类库冲突解决方案
$(document).ready(function() { var $jq = jQuery.noConflict(); $jq('#id').show(); });
- 浮点纹理 opengl
原文地址:http://wangqingyun84.blog.163.com/blog/static/790836172010323113604/ 因为 glsl部分 绑定fbo 看到要用浮点纹理,搜 ...
- oracle用sql 语句如何向表中插入时间?
有关日期的操作中,更多的是涉及系统当前时间,用sysdate表示即可,如果是插入其他非系统时间的日期类型数据的话,用to_date转换再插入就可以了.例: insert into 表(c_date) ...
- 大型web系统数据缓存设计-l转载
原文地址:http://www.wmyouxi.com/a/60368.html#ixzz3tGYG9JwC 1. 前言 在高访问量的web系统中,缓存几乎是离不开的:但是一个适当.高效的缓存方案设计 ...
- 文件名中含有连续字符abc,相应文件中也含有字符串abc
find ./ -name '*abc*' -exec grep 'abc' {} -H \; find ./ -name '*abc*' | xargs -I '{}' grep abc {} -H ...
- CMD命令进入文件夹
cmd 进入E文件夹 E: 查看文件夹目录 dir 进入某个文件夹 cd 目录
- 如何POST一个JSON格式的数据给Restful服务
在Android/java平台上实现POST一个json数据: JSONObject jsonObj = new JSONObject(); jsonObj.put("username&qu ...