1 目的界面

2、编写Android清单文件

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.itheima28.simpleadapterdemo"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk

android:minSdkVersion="8"

android:targetSdkVersion="19" />

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.itheima28.simpleadapterdemo.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

3 activity_main.xml的文件内容

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity" >

<ListView

android:id="@+id/listview"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</RelativeLayout>

4 listview_item.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="wrap_content"

android:gravity="center_vertical"

android:orientation="horizontal"

android:padding="10dip" >

<ImageView

android:id="@+id/iv_icon"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/f007" />

<TextView

android:id="@+id/tv_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="10dip"

android:text="张三"

android:textColor="#FF0000"

android:textSize="23sp"/>

</LinearLayout>

5 MainActivity的内容如下:

package com.itheima28.simpleadapterdemo;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import android.os.Bundle;

import android.support.v7.app.ActionBarActivity;

import android.widget.ListView;

import android.widget.SimpleAdapter;

public class MainActivity extends ActionBarActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ListView mListView = (ListView) findViewById(R.id.listview);

List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();

Map<String, Object> map = new HashMap<String,Object>();

map.put("name", "张三1");

map.put("icon", R.drawable.f007);

data.add(map);

map = new HashMap<String,Object>();

map.put("name", "张三2");

map.put("icon", R.drawable.f007);

data.add(map);

map = new HashMap<String,Object>();

map.put("name", "张三3");

map.put("icon", R.drawable.f007);

data.add(map);

map = new HashMap<String,Object>();

map.put("name", "张三4");

map.put("icon", R.drawable.f007);

data.add(map);

map = new HashMap<String,Object>();

map.put("name", "张三5");

map.put("icon", R.drawable.f007);

data.add(map);

SimpleAdapter adapter = new SimpleAdapter(

this,   //上下文

data,   //listView绑定的数据

R.layout.listview_item, //listview的子条目的布局的id

new String[]{"name","icon"}, //data数据中的map集合里的key

new int[]{R.id.tv_name,R.id.iv_icon}); //resource中的id

mListView.setAdapter(adapter);

}

}

08_Android中的SimpleAdapter的使用的更多相关文章

  1. 04 SimpleAdapter

    <span style="font-size:18px;">package com.fmyboke; import java.util.ArrayList; impor ...

  2. Android开发(十四)——SimpleAdapter与自定义控件

    ListView中可以使用SimpleAdapter进行数据与视图的绑定,但都是对已有的系统控件的绑定,如果自定义空间直接使用SimpleAdapter绑定,则会报错. 如,使用CircleImage ...

  3. ListActivity的使用

    Android中经常用到列表,ListActivity是实现列表的一种好方法. 使用ListActivity的方法,首先定义布局文件: <?xml version="1.0" ...

  4. View相关知识学习总结

    (一)LayoutInflater原理分析 LayoutInflater主要用于加载布局.通常情况下,加载布局的任务都是在Activity中调用setContentView()方法来完成的,该方法内部 ...

  5. 打造Android万能上拉下拉刷新框架--XRefreshView(三)

    转载请注明出处:http://blog.csdn.net/footballclub/ 打造Android万能上拉下拉刷新框架–XRefreshView(一) 打造Android万能上拉下拉刷新框架–X ...

  6. 安卓第四次作业——简单校园二手交易APP

    一.项目团队 团队成员 姓名:汤文涛 学号:1600802129 班级:计算机164班 博客地址:https://www.cnblogs.com/taotao01/ 姓名:杨圣豪 学号:1600802 ...

  7. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

  8. Android应用项目中BaseAdapter、SimpleAdapter和ArrayAdapter中的三种适配器

    一.写在前面: 本次我们来讲解一下Android应用中三个适配器:BaseAdapter.SimpleAdapter和ArrayAdapter.其中常见的是BaseAdapter,也是个人推荐使用的适 ...

  9. XML文件解析并利用SimpleAdapter将解析结果显示在Activity中

    首先创建一个实体类 Mp3Info用来存储解析的XML文件中的内容: public class Mp3Info implements Serializable{ private static fina ...

随机推荐

  1. Linux完全卸载Oracle的操作步骤

    卸载步骤如下:1.运行$ORACLE_HOME/bin/localconfig delete2.rm -rf $ORACLE_BASE/*3.rm -f /etc/oraInst.loc etc/or ...

  2. 背包DP入门小笔记01背包

    FJUT OJ 2347 http://59.77.139.92/Problem.jsp?pid=2347 采药 TimeLimit:1000MS  MemoryLimit:128MB 64-bit ...

  3. 导出和导入Docker容器

    导出容器 如果要导出本地某个容器,可以使用 docker export 命令. $ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATU ...

  4. 20160220.CCPP体系详解(0030天)

    程序片段(01):对称.c 内容概要:对称 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h ...

  5. Windows 10下Markdown不能显示预览

    Windows 10下Markdown不能显示预览 结局办法 下载awesomium的SDK,安装后重启Markdown即可 实测最新版本的SDK不行,建议安装1.6.6 下载地址:http://ww ...

  6. Android开发学习之路--Android Studio cmake编译ffmpeg

      最新的android studio2.2引入了cmake可以很好地实现ndk的编写.这里使用最新的方式,对于以前的android下的ndk编译什么的可以参考之前的文章:Android开发学习之路– ...

  7. iOS 应用打包命令一览

    文章转载自:http://www.jianshu.com/p/5d59966eaecc 文章排版部分根据自己的理解做了一些修改. 各种命令的简介 使用命令打包iOS 应用一般会用到 xcodebuli ...

  8. Android TV开发总结(一)构建一个TV app前要知道的事儿

    转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52792562 前言:近年来,智能 ...

  9. Java提升篇之反射的原理(二)

    Java提升篇之通过反射越过泛型检查 /* *问题:在一个ArrayList<Integer>对象中,在这个集合中添加一个字符串. */ 在我们还没有学反射前,遇到这个问题都是无法实现的, ...

  10. Nginx的负载均衡 - 保持会话 (ip_hash)

    Nginx版本:1.9.1 我的博客:http://blog.csdn.net/zhangskd 算法介绍 ip_hash算法的原理很简单,根据请求所属的客户端IP计算得到一个数值,然后把请求发往该数 ...