ArrayAdapater不同参数使用的细节
来源:互联网 发布:软件协议是什么 编辑:程序博客网 时间:2024/06/02 00:34
Adapter是连接后端数据和前端显示的适配器接口,适配器是数据和视图之间的桥梁。
在常见的View(ListView,GridView)等地方都需要用到Adapter。android提供的
三种Adapter主要有ArrayAdapter,SimpleAdapter,SimpleCursorAdapter。
其中ArrayAdapter的构造方法参数有多种,在使用时一般用如下两种,分别有三个、四个参数:
(1)ArrayAdapter<String>(context,textViewResourceId, objects)
(2)ArrayAdapter<String>(context,resource, textViewResourceId, objects)
官方对参数的解释是:
- Parameters:
- context The current context.
- resource The resource ID for a layout file containing a layout to use when instantiating views.
- textViewResourceId The id of the TextView within the layout resource to be populated
- objects The objects to represent in the ListView.
- 其实resource 主要就是layout的布局,也就是哪个XML布局文件
textViewResourceId 主要就是布局文件下的TextView
下面看一下两者之间的使用区别:
(1)ArrayAdapter<String>(this, R.layout.list_item_1, objects)
(2)ArrayAdapter<String>(this,R.layout.list_item_2,R.id.lv,objects)
list_item_1:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>list_item_2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>可以发现三参数中的textViewResourceId,直接用一个只含有TextView
的布局文件即可,且不能用含有LinearLayout布局的条目。四参数中的textViewResourceId则使用resource布局文件下id=lv的TextView。
- ArrayAdapater不同参数使用的细节
- android:lineSpacingMultiplier在不同版本Eclipse下的使用细节。
- SQL中不同的参数使用不同的条件
- PHP中CURL的CURLOPT_POSTFIELDS参数使用细节
- Path路径小细节:转发和重定向的Path参数的意义却是不同的
- NSDictionary 封装参数的细节
- 要使用不同的参数的函数的函数指针
- NET命令的不同参数的使用技巧
- python使用requests模块参数编码的不同处理
- echarts实现双y轴,并实现不同的参数使用不同的y轴
- sizeof的使用细节
- Latex的使用细节
- UIButton的使用细节
- SHFileOperation的使用细节
- gson的使用细节
- NSOperation的使用细节
- block的使用细节
- 使用ftpclient的细节
- linux实用的日志分析脚本
- jQuery操作Select
- HTML 参考手册
- 宅急送项目第六天笔记!
- Eclipse自动编译NDK/JNI的三种方法
- ArrayAdapater不同参数使用的细节
- 90分钟内完成全天工作
- 页面提交浏览器地址栏的链接多一个问号
- JVM 线程堆栈分析过程详解
- Java中堆内存和栈内存详解
- Android内存机制分析下篇:分析APP内存使用情况
- 前端框架之Bootstrap
- LeetCode算法题之Implement strStr()
- fgets与scanf的区别