import android.view.LayoutInflater;

它的作用就是这样地:
LayoutInflater inflater = (LayoutInflater)    mContext.getSystemService(LAYOUT_INFLATER_SERVICE);        View layout = inflater.inflate(R.layout.custom_dialog,null);           TextView text = (TextView) layout.findViewById(R.id.text); 


其实,它的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout下xml布局文件,并且实例化!而findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等)。


获取LayoutInflater的方式有以下几种:
【1】
LayoutInflater inflater = (LayoutInflater)    mContext.getSystemService(LAYOUT_INFLATER_SERVICE);

【2】
LayoutInflater inflater = getLayoutInflater();inflater = LayoutInflater.from(context);


实质以上两种是一样的:
public static LayoutInflater from(Context context) {       LayoutInflater LayoutInflater =               (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);       if (LayoutInflater == null) {           throw new AssertionError("LayoutInflater not found.");       }       return LayoutInflater;   } 



更多相关文章

  1. android中showSoftInput不起作用
  2. 在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法
  3. android中.classpath和.project作用
  4. Linux文件的特殊权限位SUID、SGID作用及编程设置/读取
  5. 关于Android的selector背景选择器的配置不起作用的问题
  6. Android环境变量作用--命令行操作(ADB、AVD等)
  7. Android ImageView控件的MaxWidth、MaxHeight不起作用

随机推荐

  1. Android(安卓)Dialog 对话框详解及示例代
  2. Android8.0 Oreo新特性
  3. Android(安卓)View的onTouch、onClick和o
  4. Android中保存图片到本地功能实现
  5. Android的一个自定义的动态添加Dialog类
  6. Android中Adapter使用ViewHolder优化
  7. 设置程序[置顶] android(10)_android权限
  8. 13_拍照、录像和音频
  9. Android中persistent属性用法详解
  10. Android(安卓)实用的 Linux命令