zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    Silverlight 4版本升级到4.0.60531.0
    Silverlight实例教程 理解Navigation导航框架Page类
    微软官方在线培训课程汇总2011版
    分享Silverlight/WPF/Windows Phone一周学习导读(07月11日07月17日)
    Linux内核简介
    Brief Summary of IaaS, PaaS, SaaS
    On Amazon EC2's Underlying Architecture
    Linux进程管理(2)
    一个诡异的时间问题追查[转]
    查看一个进程打开了哪些文件的命令
  • 原文地址:https://www.cnblogs.com/niray/p/3815059.html
Copyright © 2011-2022 走看看