1.listview的数据填充可以通过ArrayAdapter,SimpleAdapter,也可以是一个xml文件,但是ArrayAdapter与SimpleAdapter的区别是:
2 ArrayAdapter可以让一个类继承自BaseAdapter之后,可以对listview中的button,checkBox等空间进行事件的监听操作,而SimpleAdapter只能对listview填充数据的一个操作,不具有对空间的事件监听功能。
3 下面通过实例进行说明(是通过自定义listview):
(1)SimpleAdapter:
listview中每一项中的数据的布局文件及时listItem.xml
<?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:gravity="center_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:focusable="false"
android:id="@+id/textView1"
android:textSize="14dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> <TextView
android:focusable="false"
android:id="@+id/textView2"
android:textSize="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>
<ImageButton
android:focusable="true"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imagebutton1"/>
</LinearLayout> lisview的布局文件(list.xml): <?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" >
<ListView
android:descendantFocusability="afterDescendants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/list"
android:scrollbars="vertical"></ListView>
</LinearLayout> //此方法是从sdcard的RecorderFile文件夹中扫描到以.3gp结尾的文件存放到一个集合中
public List<Map<String,Object>> serachFile()
{
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
File file=new File(Environment.getExternalStorageDirectory().toString()+"/RecorderFile");
File[] files=file.listFiles(); for(int i=0;i<files.length;i++)
{
if(files[i].getName().endsWith(".3gp"))
{
//这个map对象必须在这里声明创建,否侧会出现数据重复显示一项数据
Map<String,Object> map=new HashMap<String,Object>();
map.put("img", R.drawable.ic_launcher);
map.put("title", files[i].getName());
map.put("info", files[i].getPath());
map.put("button", R.drawable.control_play_blue);
list.add(map);
}
}
System.out.println("**************"+Environment.getExternalStorageState());
}
return list;
} 下面是listview中最要的一部是数据填充器(SimpleAdapter)
    SimpleAdapter simpleAdapter=new SimpleAdapter(this, serachFile(),
88            R.layout.listitem,new String[]{"img","title","info","button"},
  new int[]{R.id.imageView1,R.id.textView1,R.id.textView2,R.id.playButton})
参数:
91 1.当前的类对象,可以通过thisl表示
92 2.这个参数是一个集合对象儿上面的方法正好是返回一个集合对象所以是serachFile()
93 3。这个是listview中每一项中的组件的布局文件
94 4.是map对象的以键值对以字符数组的形式
95 5.这个参数是,listview中每一项中的组件的id,把他以数组的方式存放
96 只有通过findviewById()找到listview控件并设置数据源。listview.setAdapter(simpleAdapter)这样就可以把数据填充到listview空间中

Android中ListView同过自定义布局并使用SimpleAdapter的方式实现数据的绑定的更多相关文章

  1. Android 中的AlertDialog使用自定义布局

    Android使用指定的View开发弹窗功能 Android开发中进程会使用到我们的AlertDialog,但是比较可惜的是我们的Android原生的AlertDialog的效果又比较的简陋,这个时候 ...

  2. android中ListView点击和里边按钮点击不能同时生效问题解决

    今天遇到一个问题:android中ListView点击和里边button点击不能同时生效问题解决. 原因是: listView 在开始绘制的时候,系统首先调用getCount()函数,根据他的返回值得 ...

  3. Android中ListView控件的使用

    Android中ListView控件的使用 ListView展示数据的原理 在Android中,其实ListView就相当于web中的jsp,Adapter是适配器,它就相当于web中的Servlet ...

  4. Android中Listview点击item不变颜色以及设置listselector 无效

    Android中Listview点击item不变颜色以及设置listselector 无效 这是同一个问题,Listview中点击item是会变颜色的,因为listview设置了默认的listsele ...

  5. android中ListView控件&&onItemClick事件中获取listView传递的数据

    http://blog.csdn.net/aben_2005/article/details/6592205 本文转载自:android中ListView控件&&onItemClick ...

  6. Android中ListView无法点击

    Android中ListView无法点击 转自:http://xqjay19910131-yahoo-cn.iteye.com/blog/1319502   问题描述: ListView中Item加入 ...

  7. Android中ListView实现图文并列并且自定义分割线(完善仿微信APP)

    昨天的(今天凌晨)的博文<Android中Fragment和ViewPager那点事儿>中,我们通过使用Fragment和ViewPager模仿实现了微信的布局框架.今天我们来通过使用Li ...

  8. Android中ListView的几种常见的优化方法

    Android中的ListView应该算是布局中几种最常用的组件之一了,使用也十分方便,下面将介绍ListView几种比较常见的优化方法: 首先我们给出一个没有任何优化的Listview的Adapte ...

  9. Android中ListView的各种显示效果

    在android应用开发中,ListView是使用频率非常高的一个组件,基本上稍微复杂点的布局都会用到它,利用它可以让你的界面美观,有层次 .ListView可以用来作为数据显示的容器,也可以作为界面 ...

随机推荐

  1. Android Toast封装

    package com.whoop.mobile.trace.util; import android.content.Context; import android.content.res.Reso ...

  2. Windows下连接调试Asus Nexus 7 Tablet

    Linux和mac下都能够直接连接,可是windows下必须下驱动.官网上的driver无论用.管用的是 https://drive.google.com/uc?id=0Bw8B2a85Qa1jSld ...

  3. root用户改动普通用户文件

    首先使用别的用户登录入LINUX系统,切换成root用户.进入到须要改动的用户主文件夹,对该用户文件夹下的文件进行改动

  4. JDK动态代理实现简单AOP--转

    JDK 动态代理是 java 反射的一个重要特性.它在某种方面为 java 提供了动态性的特性,给应用带来了无限的空间.大名鼎鼎的 Hessian . Spring AOP 基于动态代理实现.本文将简 ...

  5. java图片处理工具类

    直接上代码: package com.zxd.tool; /** * Created by zhang on 14-3-1. * 图片的常用操作类 */ import java.awt.AlphaCo ...

  6. git clone之后自动checkout文件处理

    这个问题发生是因为不同操作系统的行结束符不一致导致的,可在clone之后在仓库根目录修改.gitattributes文件 简单处理的话,注释* text=auto这行即可.也可根据不同系统,做相应设定 ...

  7. Chapter 8. Introduction to multi-project builds 多工程构建介绍

    Only the smallest of projects has a single build file and source tree, unless it happens to be a mas ...

  8. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  9. ios 中如何应对UIScrollView快速滑动(暴力用户,暴力测试)

    1.实现UIScrollViewDelegate 开始滑动: - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView 滑动 ...

  10. 小学生之浅谈Struts2与struts1的运行机制

    Struts1工作原理图: 1.初始化:struts框架的总控制器ActionServlet是一个Servlet,它在web.xml中配置成自动启动的Servlet,在启动时总控制器会读取配置文件(s ...