Android——ListView
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的更多相关文章
- android ListView 九大重要属性详细分析、
		android ListView 九大重要属性详细分析. 1.android ListView 一些重要属性详解,兄弟朋友可以参考一下. 首先是stackFromBottom属性,这只该属性之后你做好 ... 
- Android ListView onItemClick Not Work
		Android ListView onItemClick Not Work ListView item中有Button和RadioButton的时候,它的Item点击事件不起作用,需要设置item的属 ... 
- 【腾讯Bugly干货分享】Android ListView与RecyclerView对比浅析--缓存机制
		本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5811d3e3ab10c62013697408 作者:黄宁源 一,背景 Recy ... 
- Android ListView 常用技巧
		Android ListView 常用技巧 Android TextView 常用技巧 1.使用ViewHolder提高效率 ViewHolder模式充分利用了ListView的视图缓存机制,避免了每 ... 
- Android listview addHeaderView 和 addFooterView 详解
		addHeaderView()方法:主要是向listView的头部添加布局addFooterView()方法:主要是向listView的底部添加布局 需要注意的是添加布局的时候应该添加从父容器开始添加 ... 
- Android ListView滑动过程中图片显示重复错乱闪烁问题解决
		最新内容建议直接访问原文:Android ListView滑动过程中图片显示重复错乱闪烁问题解决 主要分析Android ListView滚动过程中图片显示重复.错乱.闪烁的原因及解决方法,顺带提及L ... 
- Android --ListView分页
		参考博客:Android ListView分页加载(服务端+android端)Demo 监听OnScrollListener事件 class OnListScrollListener implemen ... 
- Android ListView ListActivity PreferenceActivity背景变黑的问题ZT
		Android ListView ListActivity PreferenceActivity背景变黑的问题 ListView在滚动时背景会变暗甚至变黑,这个要从Listview的效果说起,默认的L ... 
- android listview去掉分割线
		1:android listview去掉分割线 1>设置android:divider="@null" 2>android:divider="#0000000 ... 
- 【转】android ListView 几个重要属性
		android ListView 几个重要属性 分类: Android2012-03-08 19:25 19324人阅读 评论(5) 收藏 举报 listviewandroid活动javalistnu ... 
随机推荐
- DB2使用笔记
			1.赋予用户LOAD权限的步骤 使用实例用户db2inst1登录数据库: 使用命令db2 update dbm cfg using sysadm_group dasadm1给管理员用户组d ... 
- Apache Jmeter(1)
			Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试但后来扩展到其他测试领域. 它可以用于测试静态和动态资源例如静态文件. ... 
- 解决uploadify多图片上传部分图片丢失,且不提示任何错误的问题
			这两天用到uploadify的flash版本进行批量图片上传并生成缩略图的功能,之前用uploadify用的好好的,这次突然出现了一个奇怪的问题. 问题描述如下:当我选择单个图片上传的时候,图片上传都 ... 
- 升级到EntityFramework 6的注意事项
			参考: http://social.msdn.microsoft.com/Forums/vstudio/en-US/aa542153-b2a5-4b14-98a3-572f7b028c61/updat ... 
- STM32串口USART1的使用方法
			前言: 通用同步异步收发器(USART)提供了一种灵活的方法来与使用工业标准NR 异步串行数据格式的外部设备之间进行全双工数据交换. USART利用分数波特率发生器提供宽范围的 波特率选择,支持同 ... 
- mysql innoDB 与 myISAM
			转载文章 出处 http://www.pureweber.com/article/myisam-vs-innodb/ 使用MySQL当然会接触到MySQL的存储引擎,在新建数据库和新建数据表的时候都 ... 
- osmocom-bb中用osmocon刷入固件命令那些参数你都弄懂了吗?
			转载留做备份,原文地址:http://92ez.com/?action=show&id=23341 首先找到osmocon.c这个源文件,具体目录在这里 osmocom-bb/src/host ... 
- 过期邮件替换SQL
- 简单学习:repo入门
			一:关于repo repo是Google开发的用于管理Android版本库的一个工具,repo并不是用于取代git,而是用Python对git进行了一定的封装,简化了对多个Git版本库的管理.对于re ... 
- Linux怎么使用添加的新硬盘
			一.磁盘分区 装过系统后第一块磁盘的设备号是/dev/sda,在你添加一个新的磁盘后一般情况下是/dev/sdb *******进入fdisk界面***** # fdisk /dev/sdbDevic ... 
