ArrayAdapter比较简单,但它只能用于显示文字。而SimpleAdapter则有很强的扩展性,可以自定义出各种效果
ArrayAdapter;的数据可以是数组或者是队列
// 获得下拉框对象
AutoCompleteTextView textview = (AutoCompleteTextView) this .findViewById(R.id.textView); //下拉框对象需要一个数据源,使用list队列添加数据 String[] array = { "设置", "wlan", "移动网络", "声音","显示","存储","电池","引用程序" }; /*第一个:上下文对象 第二个:布局的样式 第三个:数据*/ ArrayAdapter<String> arrayAdapter =new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,array ); //设置适配器 textview.setAdapter(arrayAdapter);
SimpleAdapter;可以有图片和文字,一时难以理解
// 参数1:上下文
// 参数2:图片和文字数据
// 参数3:用来显示List中一条数据的布局文件
// 参数4:HashMap中K的数组
// 参数5:元素的布局文件中的视图id
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.grid_item,from,to);
得到参数二;
// 获得数据源 ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); //图片资源 static int[] imgs = { R.drawable.a1, R.drawable.a2, R.drawable.a3, R.drawable.a4, R.drawable.a5, R.drawable.a6, R.drawable.a7, R.drawable.a8, R.drawable.a9 }; //遍历图片 for(int i=0;i<imgs.length;i++){ HashMap<String, Object> map =new HashMap<String, Object>(); map.put("k1", imgs[i]); map.put("k2", "程序"+i); list.add(map); }
参数三; 用来显示List中一条数据的布局文件
重新定义一个布局文件,
grid_item.xml
<ImageView android:id="@+id/img" android:layout_width="50dp" android:layout_height="50dp" /> <TextView android:id="@+id/text" android:layout_width="50dp" android:layout_height="wrap_content" android:gravity="center_horizontal" />
参数四:获取HashMap中K的数组 就是k1和k2
String[] from={"k1","k2"};
参数五:获取布局文件的id
int[] to = { R.id.img, R.id.text };
由于布局文件已经在SimpleAdapter创建时创建了对象所以直接R.id.img, R.id.text 就获取到grid_item.xml中的id
相关推荐
ArrayAdapter和simpleAdapter的回顾,好长时间都没有写android了,今天出来溜溜,这个写的是最初的功能。 就是listview。simpleAdapter是左图片右文本、 这个适合初学者玩下。
ArrayAdapter和SimpleAdapter是适配器的两种。ListView控件是最常用的控件之一,ListView的经常使用ArrayAdapter和SimpleAdapter来加载数据源。ArrayAdapter(数组适配器)用作展现简单的纯文字列表;SimpleAdapter...
ArrayAdapter和SimpleAdapter使用,详细了解请移步http://blog.csdn.net/zxc514257857/article/details/70217422
Android中ListView常用的两种适配器ArrayAdapter和SimpleAdapter使用
NULL 博文链接:https://aarongo.iteye.com/blog/1919251
ListView 与ArrayAdapter,BaseAdapter,SimpleAdapter,SimpleCursorAdapter配合使用实例。
ListView加载ArrayAdapter和SimpleAdapter
根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter 其中以ArrayAdapter最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。SimpleCursorAdapter...
AutoCompleteTextView和adapter的使用,里面用了arrayAdapter和simpleAdapter
理解适配器的使用原理,掌握ListView的使用方法,通过编程实现SimpleAdapter和BaseAdapter在简单订餐程序中的应用。 【实践要求】 1.理解Adapter的工作原理,了解ArrayAdapter、SimpleAdapter、CursorAdapter和...
传智播客_Andorid教程_20天从零到精通精通Android开发视频_第05天 1、SQlite数据库简介 ...10、ArrayAdapter和SimpleAdapter的使用 11、通过listview展示数据库数据 获取更多教程资料添加qq 2369773854
android 的用arrayAdapter和SimpleAdapter的两种ListView 入门专用 不喜勿喷
简单的listview,有ArrayAdapter,SimpleAdapter和SimpleCursorAdapter。
代码中主要介绍ListView的三种配置方法,包括ArrayAdapter,SimpleAdapter和BaseAdapter
ListView基本使用,ArrayAdapter、SimpleAdapter、BaseAdapter
三个示例代码,分别演示了ArrayAdapter,SimpleAdapter,和BaseAdapter的用法。
简单例子比较了arrayAdapter 和simpleAdapter的区别,还加了些其他的诸如带有checkBox 的listview 等,代码比较简单,适合初学者使用。
ListView之适配器的使用包含了ArrayAdapter,SimpleAdapter ,BaseAdapter等适配器。
listView三种适配器基本的形式,ArrayAdapter\SimpleAdapter\SimpleCursorAdapter 简单的Demo