使用LayoutInflater动态加载布局和…
来源:互联网 发布:南威软件好吗 编辑:程序博客网 时间:2024/06/05 23:54
我们知道在Android中通过布局文件来描述软件的界面,而通常在Activity中都是使用setContentView()来将布局显示出来。但是如果我们在非Activity的情况下,而且需要对布局中的控件进行设置等操作,该如何处理呢?这就需要使用到动态加载布局LayoutInflater,下面ATAAW.COM来做介绍。
以一个简单布局example.xml为例,里面只有一个按钮和一个文本显示框控件。
<TextView
android:id="@+id/tview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ATAAW.COM"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="按钮"
/>
在程序中动态加载以上布局。
LayoutInflater flater = LayoutInflater.from(this);
View view = flater.inflate(R.layout.example, null);
获取布局中的控件。
button = (Button)view.findViewById(R.id.button);
textView = (TextView)view.findViewById(R.id.tview);
为Button添加事件监听。
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
textView.setText("WWW.ATAAW.COM");
}
});
一般情况下,LayoutInflater在定义适配器中使用的比较多,例如我们可以为适配器定义布局,继而在适配器的设计中对控件进行数据绑定等设置操作。
- 使用LayoutInflater动态加载布局和…
- Android布局 使用LayoutInflater动态加载布局和操作控件
- 使用LayoutInflater动态加载布局和操作控件
- Android使用LayoutInflater动态加载布局和操作控件
- LayoutInflater的使用:动态加载布局
- layoutInflater动态加载布局
- LayoutInflater 动态加载布局
- LayoutInflater 动态加载布局文件
- LayoutInflater 动态加载布局文件
- android控件学习二:使用LayoutInflater动态加载布局和操作控件
- LayoutInflater动态加载布局方法实例
- 动态加载布局LayoutInflater.inflate()源代码解析
- 【Android动态布局】之【LayoutInflater的使用】
- LayoutInflater加载布局
- LayoutInflater如何加载布局?
- LayoutInflater动态加载布局文件及视图适配器BaseAdapter
- 动态设置布局LayoutInflater
- 组件和布局加载~LayoutInflater和findViewById() 的区别
- Android之可收缩展开列表Expandabl…
- Nginx location初识
- 具动画效果的图片转换器ImageSwitc…
- Android属性gravity与layout_gravi…
- Android开发中的风格与主题的区别…
- 使用LayoutInflater动态加载布局和…
- 让Android的输入框与文本框带滚动…
- InputFilter实现EditText文本输入…
- jsp href
- Android开发中单选框控件RadioButt…
- 使用地图控件MapView如何申请apiKe…
- 提示服务Notification在Android中…
- 在Android程序代码中实现软件安装…
- 在Android中Preferences数据存储的…