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 ...
随机推荐
- [Swift2.0系列]Defer/Guard 基础语法
1.Defer Swift2.0中加入了defer新语法声明.defer译为延缓.推迟之意.那么在Swift2.0中它将被应用于什么位置呢?比如,读取某目录下的文件内容并处理数据,你需要首先定位到文件 ...
- ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出错解决方案
博客地址 http://blog.csdn.net/foxdave 近期了解MVC4的时候弄了一个简单的小工程,使用Entity Framework作为Model,F5启动调试运行的时候没有问题,但是 ...
- 使用windows远程桌面连接Windows Azure中的Ubuntu虚拟机
1.创建ubuntu虚拟机,这里同样不再赘述,创建过程和创建Windows虚拟机基本一样,只是登录可以选择密钥注入或者用户名密码(为了方便我选择了用户名密码认证),创建完成后,查看虚拟机详情中的端口信 ...
- iOS应用崩溃日志分析
转自raywenderlich 作为一名应用开发者,你是否有过如下经历? 为确保你的应用正确无误,在将其提交到应用商店之前,你必定进行了大量的测试工作.它在你的设备上也运行得很好,但是,上了应 ...
- 重拾java系列一java基础(1)
前言,不知不觉,从接触java到工作至今已有两年的时间,突然感觉自己的基础知识还很薄弱,有些知识虽然知道,但是停留在表面上,没有深挖,或者实践过,感觉掌握的很肤浅,而且时间一长,就觉得忘记了,我觉得这 ...
- [动态规划]状态压缩DP小结
1.小技巧 枚举集合S的子集:for(int i = S; i > 0; i=(i-1)&S) 枚举包含S的集合:for(int i = S; i < (1<<n); ...
- 转:Enterprise Library 4.0缓存应用程序块
英文原文:http://msdn.microsoft.com/zh-cn/library/cc511588(en-us).aspx Enterprise Library 缓存应用程序块允许开发人员在应 ...
- nginx下面部署fast-cgi和C++【原】
1.cgi文件的代码 #include "fcgi_stdio.h" #include <stdlib.h> #include <stdio.h> int ...
- Oracle PL/SQL高级应用 视图 同义词 序列
视图: 视图叫虚表,即是在哪个表上建立的视图,将那个表的数据用一条查询sql语句查出的数据展现在该视图中,对这个视图操作就是只能对该视图中的数据进行操作,该操作也会保存在建立的表中.可以理解为表上表, ...
- word 无法显示图片问题解决
1 打开Word文档,点击“Office按钮”→“Word选项”. 2 在打开的“Word选项”对话框中,点击左侧的“高级”选项卡,在右侧找到“显示文档内容”栏目,取消勾选“显示图片框”.