你的位置:首页 > 软件开发 > 操作系统 > 关于SimpleAdapter和ListView结合使用,实现列表视图的笔记

关于SimpleAdapter和ListView结合使用,实现列表视图的笔记

发布时间:2016-07-29 15:00:27
使用ListView需要为其添加适配器:  适配器有两种:1.ArrayAdapter  --用于单独文字显示         2.SimpleAdapter --用于文字和图片显示  这里主要记录SimpleAdapter:    先看SimpleAdapter的构造函数 ...

使用ListView需要为其添加适配器:

  适配器有两种:1.ArrayAdapter   --用于单独文字显示

         2.SimpleAdapter --用于文字和图片显示

  这里主要记录SimpleAdapter:

    先看SimpleAdapter的构造函数:

  SimpleAdapter(context,data,resource,from,to)

  --context:上下文,其实就是指的activity本身

  --data:数据源:一个包含了map的List集合;List里的每一个元素都是一个Map集合,Map是包含多组键值对

  --resource:布局文件,可以自己写,在R.Layout下可以获得,布局中对应元素的总和,全部可以储存在Map中

  --from:一个String[]数组,对应Map中的key元素的,类似于起名字 

  --to:在从Map中获取对应key的值后,储存进去具体的值

  下面是具体的例子

  工具:Android studio

  首先写布局文件:item.

  

<??><LinearLayout ="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="horizontal">  <ImageView    android:id="@+id/itempic"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginLeft="15dp"    android:src='/images/loading.gif' data-original="@mipmap/ic_launcher" />  <TextView    android:id="@+id/itemtext"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="demo"    android:textSize="40sp" /></LinearLayout>

原标题:关于SimpleAdapter和ListView结合使用,实现列表视图的笔记

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。