1.ArryAdapter:

arry_adapter的layout文件:

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

     <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"/>

activity_test6的layout文件:

 <?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hanqi.testapp2.TestActivity6"> <ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv_1"></ListView>
</LinearLayout>

java类:

 package com.hanqi.testapp2;

 import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView; public class TestActivity6 extends AppCompatActivity { ListView lv_1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test6);
ListView lv_1 = (ListView)findViewById(R.id.lv_1); //1.数据集合 layout文件
String[] strings = {"A1","A2","A3","A4","A5","A6","A7","A8","A9",
"A1","A2","A3","A4","A5","A6","A7","A8","A9"};
//2.创建Adpter
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.arry_adapter,strings);
//3.绑定到ListView
lv_1.setAdapter(arrayAdapter);
}
}

效果图:

2.SimpleAdapter:

simple_adapter的layout文件:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"> <ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/f1"
android:id="@+id/iv_2"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:gravity="center_vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="名字=aaa"
android:id="@+id/tv_7"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="内容=aaa"
android:id="@+id/tv_8"/>
</LinearLayout>
</LinearLayout>

activity_test7的layout文件:

 <?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hanqi.testapp2.TestActivity7"> <ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv_2"></ListView>
</LinearLayout>

java类:

 package com.hanqi.testapp2;

 import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; public class TestActivity7 extends AppCompatActivity { ListView lv_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test7);
lv_2 = (ListView)findViewById(R.id.lv_2);
//1.数据集合 layout
List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>();
Map<String,Object> map = new HashMap<String,Object>();
map.put("img",R.drawable.f1);
map.put("name","美食1");
map.put("content","美食1的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f2);
map.put("name","美食2");
map.put("content","美食2的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f3);
map.put("name","美食3");
map.put("content","美食3的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f4);
map.put("name","美食4");
map.put("content","美食4的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f5);
map.put("name","美食5");
map.put("content","美食5的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f6);
map.put("name","美食6");
map.put("content","美食6的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f8);
map.put("name","美食8");
map.put("content","美食8的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f9);
map.put("name","美食9");
map.put("content","美食9的介绍");
lm.add(map); map = new HashMap<String,Object>();
map.put("img",R.drawable.f10);
map.put("name","美食10");
map.put("content","美食10的介绍");
lm.add(map);
//数组 key的数组
String[]strings = {"img","name","content"};
int[]ids = {R.id.iv_2,R.id.tv_7,R.id.tv_8};
//2.创建Adapter
SimpleAdapter simpleAdapter = new SimpleAdapter(this,
lm,R.layout.simple_adapter,strings,ids);
lv_2.setAdapter(simpleAdapter);
}
}

效果图:

Android——ListView的更多相关文章

  1. android ListView 九大重要属性详细分析、

    android ListView 九大重要属性详细分析. 1.android ListView 一些重要属性详解,兄弟朋友可以参考一下. 首先是stackFromBottom属性,这只该属性之后你做好 ...

  2. Android ListView onItemClick Not Work

    Android ListView onItemClick Not Work ListView item中有Button和RadioButton的时候,它的Item点击事件不起作用,需要设置item的属 ...

  3. 【腾讯Bugly干货分享】Android ListView与RecyclerView对比浅析--缓存机制

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5811d3e3ab10c62013697408 作者:黄宁源 一,背景 Recy ...

  4. Android ListView 常用技巧

    Android ListView 常用技巧 Android TextView 常用技巧 1.使用ViewHolder提高效率 ViewHolder模式充分利用了ListView的视图缓存机制,避免了每 ...

  5. Android listview addHeaderView 和 addFooterView 详解

    addHeaderView()方法:主要是向listView的头部添加布局addFooterView()方法:主要是向listView的底部添加布局 需要注意的是添加布局的时候应该添加从父容器开始添加 ...

  6. Android ListView滑动过程中图片显示重复错乱闪烁问题解决

    最新内容建议直接访问原文:Android ListView滑动过程中图片显示重复错乱闪烁问题解决 主要分析Android ListView滚动过程中图片显示重复.错乱.闪烁的原因及解决方法,顺带提及L ...

  7. Android --ListView分页

    参考博客:Android ListView分页加载(服务端+android端)Demo 监听OnScrollListener事件 class OnListScrollListener implemen ...

  8. Android ListView ListActivity PreferenceActivity背景变黑的问题ZT

    Android ListView ListActivity PreferenceActivity背景变黑的问题 ListView在滚动时背景会变暗甚至变黑,这个要从Listview的效果说起,默认的L ...

  9. android listview去掉分割线

    1:android listview去掉分割线 1>设置android:divider="@null" 2>android:divider="#0000000 ...

  10. 【转】android ListView 几个重要属性

    android ListView 几个重要属性 分类: Android2012-03-08 19:25 19324人阅读 评论(5) 收藏 举报 listviewandroid活动javalistnu ...

随机推荐

  1. Web体系=资源+URI+表示

    概述 Web有三个核心概念:资源(Resource).URI(UniformResource Identifer,统一资源标识符).表示(Representation).一个资源由一个URI进行标识. ...

  2. SharePoint 列表应用实例 - 显示约束

    博客地址:http://blog.csdn.net/FoxDave 有时会碰到这样的需求,比如上传周报到文档库,周报只能领导和自己看到,其他同事是看不到的.通常我们开发的人遇到这种情况条件反射地想到的 ...

  3. Deployment failed due to an error in FastDev assembly synchronization.

    在编译的时候发生Assembly synchronization error,显示信息为:Deployment failed due to an error in FastDev assembly s ...

  4. Tomcat的目录结构(二)

    一.Tomcat的目录结构 bin:启动和关闭Tomcat的bat文件 conf:配置文件 server.xml:配置和server相关的信息,比如:Tomcat启动的端口号,配置Host,配置Con ...

  5. LNA和PA

    低噪声放大器(Low Noise Amplifier) -------------LNA 功率放大器(Power Amplifier)---------------------PA LNA是低噪声放大 ...

  6. HTML的窗口分帧

    下面通过一个后台管理的部分设计来说明窗口分帧 frameset.html代码 <!-- <frameset>标签(常用来做后台管理界面) 属性:rows(行).cols(列).可以使 ...

  7. 13年省赛-B题-连通分量

    题意:求从1到N是否存在一条路,可以遍历每个节点. 思路:求任意两点之间是否通畅即可: 疑惑:完全暴力,bfs但是TLE,问题在于求连通分量(PS:不会)贴别人代码,先保存着. #include &l ...

  8. H5实现俄罗斯方块(二)

    对应的js 1.封装操作dom的js: (function (document) { //游戏的实例 var gameInst; /**封装一个返回原型的DOM对象 */ function DomOb ...

  9. swift初识

    介绍: Swift是苹果2014年推出的全新编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程不仅保留了Objc很多语言特性,他也借鉴了多种现代化语言的特点,在其 ...

  10. 自从学了SQL编程,哪里不会点哪里!!!

    在学习SQL编程前,先给大家分享几个段子吧,咱先乐呵乐呵! <桃花庵--程序员版> 写字楼里写字间,写字间中程序员:程序人员写程序,又将程序换酒钱: 酒醒只在屏前坐,酒醉还来屏下眠:酒醉酒 ...