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. SKView类

    继承自 UIView:UIResponder:NSObject 符合 NSCoding(UIView)UIAppearance(UIView)UIAppearanceContainer(UIView) ...

  2. 日积月累:ProguardGui进行jar包代码混淆

    前面文章<Proguard进行源代码混淆>讲解过怎么使用Proguard工具对Android的源代码进行混淆的方法(感兴趣的朋友可以访问:http://blog.csdn.net/p106 ...

  3. [AngularJS] Design Pattern: Simple Mediator

    We're going to use rootScope emit here to send out events and then we're going to listen for them in ...

  4. mysql 变量set

    在游标循环中,使用使用select into 变量var时,再判断var isnull 或者length(var)=0时,跳出循环. 解决方式: 使用set var=(select id from t ...

  5. 初识web01

    Tomcat   服务器        B/S    浏览器/服务器      C/S    客户端/服务器   URI:统一资源标识符   大  广   /项目名   URL:统一资源定位符     ...

  6. TreeView绑定无限层级关系类

    protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); ...

  7. UFLDL课程学习(二)

    章节地址:http://ufldl.stanford.edu/tutorial/supervised/LogisticRegression/ 章节名称:逻辑回归 (Logisitic Regressi ...

  8. 常用hash函数

    常用的哈希函数   通用的哈希函数库有下面这些混合了加法和一位操作的字符串哈希算法.下面的这些算法在用法和功能方面各有不同,但是都可以作为学习哈希算法的实现的例子.   1.RS  从Robert S ...

  9. 将图片转换为Base64

    string Imagefilename   硬盘路径 protected string ImgToBase64String(string Imagefilename) { try { Bitmap ...

  10. C# 操作电脑 关机 重启 注销 休止 休眠

    // 关机 强制电脑10秒之内关机 //System.Diagnostics.Process.Start("shutdown", "-s -f -t 10"); ...