1.首先看下main_activity.xml。其实里面就放了一个ListView。

<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity" > <ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="" >
</ListView> </LinearLayout>

2.接着我们看下适配器中要放的布局(我们把他称之为小布局文件)。

<LinearLayout 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"
android:orientation="horizontal"
tools:context=".MainActivity" > <ImageView
android:id="@+id/imvpicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> <TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#16CCDD"
android:textSize="22sp"
android:text=""/> <TextView android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#666666"
android:textSize="16sp"
android:text=""/> </LinearLayout> </LinearLayout>

3.接着我们看下ListView代码。(activity)

package com.example.listview_simpleadapter;

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.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView; public class MainActivity extends Activity {
ListView lv = null;
ImageView imgpicture = null;
TextView tvtitle =null;
TextView tvinfo = null;
String title [] = {"图片","音乐","视频"};
String info [] = {"美辰良景,给你无限的遐思,让人感觉无限温馨……","轻曼音乐,令人如入仙境,如痴如醉……","震撼场景,360度的视觉捕获,一览无遗……"};
Integer imv[] = {R.drawable.tupian,R.drawable.yinyue,R.drawable.shiping};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] from = {"imv","title","info"};
int[] to = {R.id.imvpicture,R.id.title,R.id.info};
lv = (ListView)super.findViewById(R.id.listView1);
imgpicture = (ImageView)super.findViewById(R.id.imvpicture);
tvtitle = (TextView)super.findViewById(R.id.title);
tvinfo = (TextView)super.findViewById(R.id.info);
lv.setAdapter(new SimpleAdapter(this, getData(), R.layout.simple_small, from, to)); }
private List<? extends Map<String, ?>> getData() {
List list = new ArrayList();
for (int i = ; i<imv.length; i++){
Map map = new HashMap();
map.put("imv", imv[i]);
map.put("title", title[i]);
map.put("info", info[i]);
list.add(map);
}
return list;
}
}

4.运行结果

其实里面还可以放更多的东西,只要你想放。本文适合有基础的爱好者学习,仅供参考。由于自己现在在做项目,许多地方来不及备注,有什么不懂的地方可以留言,空了给你解答。

android中ListView_SimpleAdapter的更多相关文章

  1. Android中的LinearLayout布局

    LinearLayout : 线性布局 在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了,  线性布局是按照垂直方向(vertical)或水平方向 ...

  2. Android中BroadcastReceiver的两种注册方式(静态和动态)详解

    今天我们一起来探讨下安卓中BroadcastReceiver组件以及详细分析下它的两种注册方式. BroadcastReceiver也就是"广播接收者"的意思,顾名思义,它就是用来 ...

  3. Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP)

    之前的博文<Android中使用ExpandableListView实现好友分组>我简单介绍了使用ExpandableListView实现简单的好友分组功能,今天我们针对之前的所做的仿微信 ...

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

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

  5. Android中Fragment和ViewPager那点事儿(仿微信APP)

    在之前的博文<Android中使用ViewPager实现屏幕页面切换和引导页效果实现>和<Android中Fragment的两种创建方式>以及<Android中Fragm ...

  6. Android中Fragment与Activity之间的交互(两种实现方式)

    (未给Fragment的布局设置BackGound) 之前关于Android中Fragment的概念以及创建方式,我专门写了一篇博文<Android中Fragment的两种创建方式>,就如 ...

  7. 【月入41万】Mono For Android中使用百度地图SDK

    借助于Mono For Android技术,.Net开发者也可以使用自己熟悉的C#语言以及.Net来开发Android应用.由于Mono For Android把Android SDK中绝大部分类库都 ...

  8. mono for android中使用dapper或petapoco对sqlite进行数据操作

    在mono for android中使用dapper或petapoco,很简单,新建android 类库项目,直接把原来的文件复制过来,对Connection连接报错部分进行注释和修改就可以运行了.( ...

  9. Android开发学习之路-Android中使用RxJava

    RxJava的核心内容很简单,就是进行异步操作.类似于Handler和AsyncTask的功能,但是在代码结构上不同. RxJava使用了观察者模式和建造者模式中的链式调用(类似于C#的LINQ). ...

随机推荐

  1. [vijos P1531] 食物链

    做出的第一道NOI题目?(噗,还是看题解才会的…按某篇解题说的,这题就比我年轻四岁…T T 做的第一道IOI题目是USACO上的Packing Rectangles...这题比我还老!)对我等弱渣来说 ...

  2. 【转】Centos系统文件与用户权限分配详解ftp,nginx,php

    linux系统中权限是非常完善的一个功能了,我们如果设置不正确文件就无法使用了,像我们以一般情况需要把文件权限设置为777或644了,对于用户权 限就更加了,像素ftp,nginx,php这些我们都可 ...

  3. linux内核编译

    1,进入内核源码树,如果是第一次编译,建议清理以下内核功能选择文件: make mrproper 2,删除前一次编译的残留文件: make clean 3,配置内核功能 make menuconfig ...

  4. [C/C++]数据类型与变量

    1.类型: 1.1.简介 1.1.1.基本类型(base type)和复合类型(compound type): 复合类型是指基于其它类型定义的类型.([1].2.3 p45)那么基本类型就是复合类型基 ...

  5. 提示框alertmsg

    初始化: 1.Data属性:DOM添加属性data-toggle="alertmsg",并定义type及msg参数 示例代码: <button type="butt ...

  6. hdu4417 划分树+二分

    //Accepted 14796 KB 453 ms //划分树 //把查询的次数m打成n,也是醉了一晚上!!! //二分l--r区间第k大的数和h比较 #include <cstdio> ...

  7. Ogre 1.8 terrain 和 paging 组件

    以下转自:http://hi.baidu.com/xocoder/item/e8d87cf53d87612b753c4cfd OGRE地形生成 OGRE可以通过两个接口来生成地形,分别是void Te ...

  8. 极客DIY:开源WiFi智能手表制作

    如果你喜欢拥有一款属于自己的无线手表,那么请不要错过,相信阅读完这篇文章对你会很有帮助. 硬件规格 ESP8266(32Mbit闪存) MPU-9250(陀螺仪传感器)以及 AK8963(内置磁力计) ...

  9. UIkit框架之Uivew

    1.继承链:UIresponder:NSObject 2.通过使用 addGestureRecognizer:方法可以为视图添加手势 3.下面的属性都可以用来用于动画 @property frame ...

  10. My_Python的常用函数.

    范围生成函数 class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range ...