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.运行结果

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

最新文章

  1. sqlserver数据以及日志文件的设置小结
  2. Lunix 命令
  3. Java魔法堂:URI、URL(含URL Protocol Handler)和URN
  4. Android 开发
  5. LOGSTASH再入门第一发
  6. UNIX环境下的消息队列
  7. Using Apache Web Server with Jboss AS 7
  8. bzoj2208 [Jsoi2010]连通数(scc+bitset)
  9. OCP读书笔记(7) - 使用RMAN执行恢复
  10. UNIX基础--Shells
  11. Android support library支持包常用控件介绍(一)
  12. SqlAlchemy “Too many connections”
  13. Maven项目:Malformed POM expected START_TAG or END_TAG ........
  14. C#学习笔记(33)——批量修改word标题
  15. Vue.js 2.0生命周期
  16. python day05字典
  17. 备忘:BLOCK CORRUPTION IN SYSTEM DATAFILE
  18. HTML3/CSS基础
  19. docker redis
  20. robotframwork的WEB功能测试(一)—切换window窗口

热门文章

  1. Codeforces Round #326 (Div. 2)-Duff and Meat
  2. java的动态绑定和静态绑定
  3. Android drawBitmapMesh扭曲图像
  4. 通过获取DNS解析的未转义主机名,区分测试环境和正式环境代码
  5. .net异常小总
  6. Visual Studio环境色调配色
  7. Oracle 12c与GoldenGate 12c的一些问答
  8. ACM -二分图题目小结
  9. ALAssets的两种用法
  10. Android Priority Job Queue (Job Manager)(一)