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. lucas 定理学习

    大致意思就是求组合数C(n , m) % p的值, p为一个偶数 可以将组合数的n 和 m都理解为 p 进制的表示 n  = ak*p^k + a(k-1)*p^(k-1) + ... + a1*p ...

  2. bzoj 2595 斯坦纳树

    题目大意: 选定一些格子保证景点对应的格子通过这些格子连通,保证选定的所有格子对应的权值和最小 这是相当于理解为将所有点形成的最小生成树 这里点的个数很少,所以可以对每一个点进行状态压缩 f[st][ ...

  3. Codeforces Round #326 (Div. 2)-Duff in Love

    题意: 一个数x被定义为lovely number需要满足这样的条件:不存在一个数a(a>1),使得a的完全平方是x的因子(即x % a2  != 0). 给你一个数n,求出n的因子中为love ...

  4. mybatis写mapper文件注意事项(转)

    原文链接:http://wksandy.iteye.com/blog/1443133 xml中某些特殊符号作为内容信息时需要做转义,否则会对文件的合法性和使用造成影响 < < > & ...

  5. JVM-class文件完全解析-类索引,父类索引和索引集合

    类索引,父类索引和接口索引集合 前面介绍了class文件,从头开始的魔数,次版本号,主版本号,常量池入口,常量池,访问标志.那么再接下来的就是用来确定这个类的继承关系的类索引,父类索引和接口索引集合这 ...

  6. ODI中的临时接口

    在ODI 11g及后续的版本中,针对复杂的ETL处理,可分解为多个步骤,在中间步骤中使用临时接口,而不用建立相应的物理表,ODI会在处理过程中自动创建和删除这些中间表,从而降低ETL处理复杂度:同时, ...

  7. 【转】FFMPEG 库移植到 VC 需要的步骤

    原文:http://blog.csdn.net/leixiaohua1020/article/details/12747899 在VC下使用FFMPEG编译好的库,不仅仅是把.h,.lib,.dll拷 ...

  8. 将byte[]数组数据转换为图片用于预览显示

    假如服务器返回给你的图片信息是byte[] 然后你需要将起转换成图片显示到你的view中去: 按以下的步骤 1.将获取的byte数组保存 假如为temp[]; 2.将temp[]转化为bitmap,你 ...

  9. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  10. 用Qt图形视图框架开发拼图游戏

    用Qt的图形视图框架(Graphics View Framework)做了一个拼图游戏DEMO,演示了: QGraphicsView.QGraphicsScene.QGraphicsItem的基本用法 ...