码迷,mamicode.com
首页 > 其他好文 > 详细

Inflater与findViewById()区别

时间:2015-12-26 11:45:15      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

/**
             * 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()区别

标签:

原文地址:http://www.cnblogs.com/AceIsSunshineRain/p/5077746.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!