The difference between LayoutInflater.inflate and findViewById
2015-09-12 09:30
453 查看
What is the difference between getting a reference to a widget like this:
and:
Is there also a difference when the
a root of its layout or if its just a small part of a layout?
1) Using
you are simply obtaining a reference to a
id R.id.table_row which has already been created and inflated in the current layout (where current means the
layout or the
you are defining).
2) Using
You are inflating (which means creating) a new views hierarchy based on the XML definition contained in R.layout.table_row. Since you are not passing
the parent View parameter in the inflate()method, you will need to add the resulting hierarchy manually to an existent container.
TableRow row = findViewById(R.id.table_row);
and:
TableRow row = (TableRow)LayoutInflater.from(this).inflate(R.layout.table_row, null);
Is there also a difference when the
TableRowis
a root of its layout or if its just a small part of a layout?
1) Using
TableRow row = findViewById(R.id.table_row);
you are simply obtaining a reference to a
Viewwith
id R.id.table_row which has already been created and inflated in the current layout (where current means the
Activtiy's
layout or the
Viewthat
you are defining).
2) Using
TableRow row = (TableRow)LayoutInflater.from(this).inflate(R.layout.table_row, null);
You are inflating (which means creating) a new views hierarchy based on the XML definition contained in R.layout.table_row. Since you are not passing
the parent View parameter in the inflate()method, you will need to add the resulting hierarchy manually to an existent container.
相关文章推荐
- JavaScript学习笔记(三):JavaScript也有入口Main函数
- 《剑指offer》把数组排成最小的数
- jquery(2)
- CSS3详解:transform
- 飘雪作业——index.html
- 《剑指offer》整数中1出现的次数(从1到n整数中1出现的次数)
- JSON对象和字符串之间的相互转换
- LeetCode "Perfect Squares"
- jquery(1)
- JQuery弹出层,点击按钮后弹出遮罩层,有关闭按钮
- Node.js开发入门—notepad++ for Node.js
- js实现的动画导航菜单效果代码
- 如何解决谷歌浏览器下jquery无法获取图片的尺寸
- 原生JS实现仿淘宝网左侧商品分类菜单效果代码
- JS+CSS实现大气的黑色首页导航菜单效果代码
- jQuery超精致图片轮播幻灯片特效代码分享
- js图片卷帘门导航菜单特效代码分享
- Ember.js 入门指南——handlebars基础
- Ember.js 入门指南——handlebars基础
- 【小熊刷题】Remove Nth Node From End of List <Leetcode 19, Java>