LayoutInflater与findViewById的用法

简介:

LayoutInflater与findViewById的用法有很多可比较之处。

如:他们都可以通过id返回View。

LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.custom_dialog,null);

Button button = (Button) findViewById(R.id.button);

不同之处是:LayoutInflater是用来实例化整个布局文件,而findViewById()是实例化布局文中中的View。

 



本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1399139,如需转载请自行联系原作者

相关文章
|
8月前
|
Android开发
Android LayoutInflater.from(context).inflate()方法的作用
Android LayoutInflater.from(context).inflate()方法的作用
49 0
|
XML Android开发 数据格式
Android LayoutInflater的用法详解
相信我们在开发过程中肯定接触过LayoutInflater,比如ListView的适配器里的getView方法里通过LayoutInflater.from(Context).inflater来加载xml布局,在Fragment里的onCreateView里面也是一样,加载布局一共三种方法。
1071 0
|
XML 数据库 Android开发

热门文章

最新文章