LayoutInflater和findViewById的区别

来源:互联网 发布:网络小贷牌照名单 编辑:程序博客网 时间:2024/04/28 11:26
一、概念:
inflater是膨胀的意思,在Android中,应该是“扩展”的意思,LayoutInflater的作用类似于findViewById(),不同点是,LayoutInflater是用来寻找布局文件并且进行实例化的一个方法,而findViewById是具体到一个控件的对象,所以两者的范围是不相同的。

二、代码演示:
LayoutInflater inflater = (LayoutInflater) listviewActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.listview_item, null);

三、总结:
上面的两行代码充分说明了两个方法的具体的不同之处。。。
0 0
原创粉丝点击