android中LayoutInflater详解与使用
android的LayoutInflater用来得到一个布局文件,也就是xxx.xml,而我们常用的findviewbyid是用来取得布局文件里的控件或都布局。inflater即为填充的意思,也就是说得到一个布局文件来填充(把布局文件实例化成一个View然后返回该view)。使得方法如下: 三种办法可以得到:
1:在activity中的话可以直接调用getLayoutInflater()来获得。
2:通过服务获得:getSystemService. (Context.LAYOUT_INFLATER_SERVICE)。
3:通过ayoutInflater.from(Context context)方法来获得。 三种方法的代码如下:
//方法3:
LayoutInflater lf=LayoutInflater.from(context);
View tempView=lf.inflate(R.layout.select_list, null);
//方法2:
LayoutInflater lf = (LayoutInflater)context.getSystemService.(Context.LAYOUT_INFLATER_SERVICE);
View tempView=lf.inflate(R.layout.select_list, null);
//方法1:
LayoutInflater lf = LayoutInflater.from(context);
View tempView=lf.inflate(R.layout.select_list, null);
在activity中的话上面的context可直接换成this。 得到返回的View后我们可以用他来给布局文件里的控件进行相应设置,如:
TextView id=(TextView) tempView.findViewById(R.id.id);
TextView address=(TextView) tempView.findViewById(R.id.address); id.setText("123456");
address.setText("中国湖南长沙");
上面的获得View方法有两个参数,lf.inflate(int resource, ViewGroup root),第一个为整型的资源ID,也就是xml布局文件的id,后面为根View,如果为null则只创建和返回View,如果传入root,则把创建的View加为根View的子view。 LayoutInflater可以用来得到布局文件对里面的控件进行设置,也可以可以将得到的View返回给fragment,adapter等。 总之想怎么用就怎么用了...
android中LayoutInflater详解与使用的更多相关文章
- Android中Context详解 ---- 你所不知道的Context(转)
Android中Context详解 ---- 你所不知道的Context(转) 本文出处 :http://b ...
- Android中Context详解 ---- 你所不知道的Context
转自:http://blog.csdn.net/qinjuning/article/details/7310620Android中Context详解 ---- 你所不知道的Context 大家好, ...
- android中getSystemService详解
android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监 听是否有SD卡安装及移除,ClipboardS ...
- Android中 ListView 详解(二)
本文版权归 csdn noTice501 所有,转载请详细标明原作者及出处,以示尊重! 作者:noTice501 原文:http://blog.csdn.net/notice520/article/d ...
- Android中Handle详解
上图为本人总结的Handler,网上发现一片总结很好的博客就copy过来:作为参考 Handler有何作用?如何使用? 一 .Handler作用和概念 包含线程队列和消息队列,实现异步的消息处理机制, ...
- Android中Context详解
大家好, 今天给大家介绍下我们在应用开发中最熟悉而陌生的朋友-----Context类 ,说它熟悉,是应为我们在开发中时刻的在与它打交道,例如:Service.BroadcastReceiver.A ...
- 转:Android中Context详解 ---- 你所不知道的Context
转:http://blog.csdn.net/qinjuning/article/details/7310620 转:http://blog.csdn.net/lmj623565791/article ...
- android中Actionbar详解
1.什么是Action BarAction Bar被认为是新版Android系统中最重要的交互元素,在程序运行中一直置于顶部,主要起到的作用在于:1)突出显示一些重要操作(如“最新”.“搜索”等)2) ...
- Android中IntentService详解
简单说,IntentService是继承于Service并处理异步请求的一个类,在IntentService内有一个工作线程来处理耗时操作,启动IntentService的方式和启动传统Service ...
随机推荐
- [Javascript] Adding Shapes to Maps with Leaflet and GeoJSON
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- bash shell for循环1到100 .
前言 用bash shell写程序时,经常会用到for循环,特别是从1到100这种需求,这里记录几种shell中从1到100的循环方法 方法 类c语言 for ((i=1; i<=100; ...
- android中实现简单的播放
MediaPlayer mediaPlayer1; mediaPlayer1 = MediaPlayer.create(getBaseContext(), R.raw.ic_yanyuan); med ...
- Android源码解析--Quick Search in Settings
欢迎大家加入群里交流:429664282 基于:android-6.0.1_r17 f4b8ad6 Android Settings中存在一个SearchIndexablesProvider,它提供了 ...
- C#基础篇01
vs20vs2013快捷键小节: 1>: #region #endregion(用来折叠冗余代码) 2>:Ctril+K+D快速对其代码: 3>:Ctril+K+C注释选中代码 Ct ...
- zTree判断是否为父节点
var treeObj = $.fn.zTree.getZTreeObj("tree"); var nodes = treeObj.getSelectedNodes(); if(t ...
- Sql触发器脚本
ALTER Trigger [dbo].[test] --新建触发器 On [dbo].[test1] --在test1表中创建触发器 for insert --触发条件 As --事件触发后所要做的 ...
- Eclipse中绑定java源代码
如何在Eclipse sdk中查看jar源代码如:*.jar 1.点 “window”-> "Preferences" -> "Java" -&g ...
- js的变量作用域
js不支持块级变量作用域,而是包含它们的函数的作用域, 例如: function query() { ; ; i < ; i++) { var b = i; } return b + a; } ...
- 主机访问 虚拟机web注意事项
在这里, 我通过NAT的方式, 通过主机访问虚拟机. 需要做的是, 将主机中访问的端口, 映射为虚拟机的'编辑->虚拟网络编辑器->vmnet8', 如下图 在弹出的'映射传入端口'界面中 ...