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. App Store--心酸的上线路,说说那些不可思议的被拒理由

    yoyeayoyea 您的应用包括色情内容(色情交易,色情展示). 原因是我们的销售人员,把几张艺术照放在个人相册里(头像),换成卡通头像,通过.    颜小风 被拒很正常 一次通过不正常. 之前上线 ...

  2. java基础-002

    1.Java虚拟机和“平台无关语言” Java虚拟机是可以执行字节码的虚拟机进程.Java源文件被编译成被Java虚拟机执行的字节码文件. Java被设计成允许应用程序运行在任意的平台,而不需要程序员 ...

  3. Nginx 缓存参数

    看看这下面两个指令参数: ----------------------------------------------------------------- proxy_cache_path  /ho ...

  4. mac终端下运行shell脚本

    最近公司要弄关于IOS下自动化打包的东西,研究了用命令行的形式来代替手工的方式来处理.即: 用xcodebuild 和xcrun  语法来进行脚本实现.    但由于语法的结构够了,另一个问题产生了, ...

  5. php中的include()的使用技巧

    php中的include()的使用技巧 include() 语句包括并运行指定文件. 以下文档也适用于 require().这两种结构除了在如何处理失败之外完全一样.include() 产生一个警告而 ...

  6. 破解Xamarin

    试用了一阵子Mono For Android,今天到期了,,囊中羞涩,只好破解. 说是要在vs2013的英文界面下运行破解包,不知道是真是假,下载并安装了一个. 然后又下载了破解包.是个名为xa.ra ...

  7. <button>使用注意问题

    最近在项目的上传功能下(IE8)发现了如下的错误: 2015-08-13 09:14:03,396 WARN   [WARN] [http-8080-5] : Handler execution re ...

  8. 保存现场数据和状态:onSaveInstanceState\onRestoreInstanceState\onCreate()

    当某个activity变得“容易”被系统销毁时,该activity的onSaveInstanceState就会被执行,除非该activity是被用户主动销毁的,例如当用户按BACK键的时候. 注意上面 ...

  9. OC中修饰符:宏define 常量:const extern

    const const最好理解,修饰的东西不能被修改 指针类型根据位置的不同可以理解成3种情况: I 常量指针 // 初始化之后不能赋值,指向的对象可以是任意对象,对象可变. NSString * c ...

  10. SQL语句建表、设置主键、外键、check、default、unique约束

    · 什么是数据库? 存放数据的仓库. · 数据库和数据结构有什么区别? 数据结构要解决在内存中操作数据的问题,数据库要解决在硬盘中操作数据的问题.数据结构研究一些抽象数据模型(ADT)和以及定义在该模 ...