main.xml主布局文件,代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical"  android:layout_width="fill_parent"  android:layout_height="fill_parent"  >
<TextView    android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="@string/hello"
/>  <LinearLayout  android:layout_width="wrap_content"  android:layout_height="wrap_content" >  <TextView  android:text="@string/name"  android:gravity="center"  android:layout_width="150px"  android:layout_height="wrap_content"  />  <TextView  android:text="@string/age"  android:gravity="center"  android:layout_width="170px"  android:layout_height="wrap_content"  />  </LinearLayout>  <ListView  android:id="@+id/listView"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  />  </LinearLayout>

  user.xml组件布局文件代码

<?xml version="1.0" encoding="utf-8"?>
<!-- 创建存放一行数据的组件 -->
<TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="fill_parent"  android:layout_height="wrap_content">  <TableRow>  <ImageView  android:id="@+id/image"  android:layout_width="50px"      android:layout_height="50px"   ></ImageView>  <TextView  android:id="@+id/userName"  android:gravity="center"  android:layout_height="wrap_content"  android:layout_width="150px"  ></TextView>  <TextView  android:id="@+id/userAge"  android:gravity="center"  android:layout_height="wrap_content"  android:layout_width="170px"  ></TextView>  </TableRow>
</TableLayout> 

主Activity,listView.java代码

package cn.com.android.listView;  import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;  import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;  public class listView extends Activity {  @Override  public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);  ListView listView = (ListView) findViewById(R.id.listView);  /* 参数一多,有些人就头晕了。这里解说下,各个参数的意思。 * 第一个参数 this 代表的是当前上下文,可以理解为你当前所处的activity * 第二个参数 getData() 一个包含了数据的List,注意这个List里存放的必须是map对象。simpleAdapter中的限制是这样的List<? extends Map<String, ?>> data * 第三个参数 R.layout.user 展示信息的组件 * 第四个参数 一个string数组,数组内存放的是你存放数据的map里面的key。 * 第五个参数:一个int数组,数组内存放的是你展示信息组件中,每个数据的具体展示位置,与第四个参数一一对应 * */  SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.user,  new String[]{"image","userName","userAge"}, new int[]{R.id.image,R.id.userName,R.id.userAge});  listView.setAdapter(adapter);  }  /** * @author chenzheng_java * @description 准备一些测试数据 * @return 一个包含了数据信息的hashMap集合 */  private ArrayList<HashMap<String, Object>> getData(){  ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String,Object>>();  for(int i=0;i<10;i++){  HashMap<String, Object> tempHashMap = new HashMap<String, Object>();  tempHashMap.put("image", R.drawable.icon);  tempHashMap.put("userName", "用户"+i);  tempHashMap.put("userAge", 30-i);  arrayList.add(tempHashMap);  }  return arrayList;  }  }  

strings.xml代码

<?xml version="1.0" encoding="utf-8"?>
<resources>  <string name="hello">布局列表展示</string>  <string name="app_name">列表布局</string>  <string name="name">姓名</string>  <string name="age">年龄</string>
</resources>  

废话连绵:

我们一起看看结构,一个主布局文件,一个组件布局文件,一个Activity类。

依旧分为三步:

第一步:定义布局文件,设计UI,包括寻找合适的图片了等等……

第二步:获取数据。这里用的是simpleAdapter,所以要求数据必须固定格式的

第三步:绑定数据源

然后,我们就可以看到我们想要的结果了。

android ListView布局之二(是用simpleAdapter绑定数据)相关推荐

  1. Android ListView常用用法(二)

    来自:51CTO论坛 原帖:http://mobile.51cto.com/android-254823.htm Android开发:实现带图片和checkbox的listview 项目要用到一个li ...

  2. android ProgressBar实现扫描SD卡文件 + SimpleAdapter绑定ListView

    代码 activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andro ...

  3. 【Android游戏开发十二】(保存游戏数据 [上文])详解SharedPreference 与 FIleInputStream/FileOutputStream将数据存储到SD卡中!

     李华明Himi 原创,转载务必在明显处注明: 转载自 [黑米GameDev街区] 原文链接:  http://www.himigame.com/android-game/327.html 很多童鞋说 ...

  4. android天气查询(二)之网络json数据的获取

    前面一篇文章介绍了如何使用ksoap获取天气信息,但是使用的网络资源受到了限制,所以我们这里会采用第二种方法,可以无限制的获取.http://m.weather.com.cn/data/1010101 ...

  5. android ListView适配器之SimpleAdapter的用法

    以前写过ListView的适配器中最简单的ArrayAdapter这个适配器,当listView中只需要显示一个数据时,使用ArrayAdapter适配器很方便,但是如果要向listview的每一行显 ...

  6. ListView的Adapter使用(绑定数据) 之 自定义每一项的布局去绑定数据(二)

    紧接上篇: 接下来是自定义布局的例子,我们大家先看下程序出来的效果图: 代码是: 1.     首先自定义布局,我们命名一个custom_list_layout.xml的布局文件,代码如下: < ...

  7. Android项目实战(二十):浅谈ListView悬浮头部展现效果

    Android项目实战(二十):浅谈ListView悬浮头部展现效果 原文:Android项目实战(二十):浅谈ListView悬浮头部展现效果 先看下效果:需求是 滑动列表 ,其中一部分视图(粉丝数 ...

  8. Android Listview SimpleAdapter的使用完整示例(实现用户列表)

    上一篇文章我们讲了Android Listview ArrayAdapter示例_左眼看成爱的博客-CSDN博客 这篇文章我们来讲一下 Android Listview基于SimpleAdapter的 ...

  9. Android列表用法之二:实战ListView高级用法

    在我们的项目中,并不是所有列表都是简单的使用.类似于新闻列表.QQ聊天列表等,具有图文并排的列表,每个item都有它不同的布局类型,都有其不同的实现方式.这类复杂的列表表现形式,在各类知名应用当中,不 ...

最新文章

  1. 微信小程序开发-笔记
  2. LeetCode Add Strings(大整数加法)
  3. android+qq登录测试,对于android的第三方(QQ登录,微信登录等的)测试时的签名配置...
  4. MySQL 使用自增ID主键和UUID 作为主键的优劣比较详细过程(从百万到千万表记录测试)...
  5. ES6-Generator使用与改写
  6. 杂乱无序的时间轮:有效实现定时器功能的数据结构
  7. 软件工作相关考试001---PMP等各种考试
  8. python柱状图代码_python+matplotlib实现礼盒柱状图实例代码
  9. go back go fullscreen_四款高端便携音箱TUFTON、B17、MUSIC3和GO+PLAY音质排行榜
  10. mysql表进行合法性检查_固定网格填报
  11. 路由器和iP地址的那些事
  12. ShellExecuteEx and SHELLEXECUTEINFO and ShellExecute
  13. codeforces 1384A(构造)
  14. 生命苍白无力时候遇到你,即使再难也要亲手绘出五彩生活――读《平庸的世界》有感...
  15. 一片文章带你了解汇编语言
  16. 自然语言处理NLP中文分词,词性标注,关键词提取和文本摘要
  17. 程序员健康之——护腰指南
  18. C/C++ 蛇形矩阵/蛇形填数
  19. UCOSIII移植STM32(Cotex-M4)HAL库相关问题
  20. springboot整合jd freemarker

热门文章

  1. Teechart动态设计方法
  2. linux开机启动rsync,【Linux】rsync同步文件 程序自启动
  3. mysql root 不能登录_mysql root 用户不能登录的问题
  4. bean validation校验方法参数_SpringBoot参数校验 从入门到精通 解决繁琐的参数验证工作...
  5. python中定义函数常用关键字_Python 中定义函数的关键字是 _________________ 。_学小易找答案...
  6. java 使用.aar_java - 使用grad解析aar库的传递依赖性
  7. erlang(20)-控制抽象与判断素数
  8. rust(53)-智能指针
  9. PowerBI随笔(1)-类似vlookup的合并查询
  10. AtCoder Beginner Contest 215 F - Dist Max 2