andorid 列表视图之SimpleAdapter
.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sa_1"> </ListView>
.java
package com.hanqi.application3; 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 UI4Activity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui4); ListView sa_1 = (ListView)findViewById(R.id.sa_1);
//准备数据源
List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>(); Map<String, Object> map=new HashMap<String, Object>();
map.put("image",R.drawable.an1);
map.put("name","美食图片01");
map.put("content","看上去很好吃01");
lm.add(map); map=new HashMap<String, Object>();
map.put("image",R.drawable.an2);
map.put("name","美食图片02");
map.put("content","看上去很好吃02");
lm.add(map); map=new HashMap<String, Object>();
map.put("image",R.drawable.an3);
map.put("name","美食图片03");
map.put("content","看上去很好吃03");
lm.add(map);
//1 数据源里key的数组
String[] str={"image","name","content"};
//2 layout文件里子视图的id
int[] viewid = {R.id.iv_2,R.id.tv_1,R.id.tv_2 }; SimpleAdapter sa = new SimpleAdapter(this,lm,R.layout.layout_simple,str,viewid); sa_1.setAdapter(sa);
}
}
layout_simple.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/an1"
android:id="@+id/iv_2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食图片"
android:id="@+id/tv_1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="很好吃的样子"
android:id="@+id/tv_2"/> </LinearLayout> </LinearLayout>
andorid 列表视图之SimpleAdapter的更多相关文章
- andorid 列表视图 ListView 之BaseAdapter
.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android=&qu ...
- andorid 列表视图 ListView 之ArrayAdapter
activity_ui3.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns ...
- 滚动视图、列表视图[ListView、SimpleAdapter类]
滚动视图 <ScrollView android: layout_width="fill_parent" android: layout_height="fill_ ...
- Android应用开发学习之列表视图
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 列表视图我们会经常用到,可以通过两种方式来创建列表视图,一种方式是直接使用ListView组件创建,另一种方式是通过 ...
- jQuery Mobile 列表视图(带有自动检索)
输入a: 输入b: jQuery Mobile 列表视图 jQuery Mobile 中的列表视图是标准的 HTML 列表:有序列表 (<ol>) 和无序列表 (<ul>). ...
- SharePoint 2013无代码实现列表视图的时间段动态筛选
本文介绍两种为列表视图设置时间段筛选器的方法.其中,第一个方法用于SharePoint Server,第二个方法同时还能用于SharePoint Foundation. 方法一:日期筛选器Web部件 ...
- Sharepoint 2013列表视图和字段权限扩展插件(免费下载)!
记得2014年春节期间,有博客园的网友通过QQ向我咨询Sharepoint 2013列表视图和字段权限扩展,因为之前他看到我博客介绍Sharepoint 2010列表视图和字段的权限控制扩展使用,问有 ...
- Android列表视图(List View)
Android列表视图(ListView) ListView是一个显示滚动项列表的示视图组(viewgroup),通过使用适配器(Adapter)把这些列表项自动插入到列表中.适配器比如从一个数组或是 ...
- Android——列表视图(ListView)
列表视图是android中最常用的一种视图组件,它以垂直列表的形式列出需要显示的列表项.在android中有两种方法向屏幕中添加列表视图:一种是直接使用ListView组件创建:另外一种是让Activ ...
随机推荐
- java开始的笔记
这几天第一写java的代码有些东西不是很明白: java的输入跟c/c++有点不一样,他的输入都是要首先创建每一个变量的内存,并且输入的类型不同. 就像string的那样. Scanner s=new ...
- js 统计数组中元素的个数
var all = "02 06 11 12 19 29 09 10 12 19 22 29 08 11 13 19 28 31 07 08 09 15 22 27 10 18 19 29 ...
- java.security.MessageDigest (1)
我们知道,编程中数据的传输,保存,为了考虑安全性的问题,需要将数据进行加密.我们拿数据库做例子.如果一个用户注册系统的数据库,没有对用户的信息进行保存,如,我去页面注册,输入"Vicky&q ...
- IconFont使用指南
[IconFont使用指南] 为了使用IconFont,需要先建立自己的项目. 在IconFont.cn中寻找自己喜欢的图标,加入到这个新建的项目. IconFont有三种使用方式,其中FontCla ...
- CSSの変数を使う
この文章はhttps://developer.mozilla.org/ja/docs/Web/CSS/Using_CSS_variablesを参考します. これは実験段階の機能です.この機能は複数のブ ...
- JMeter学习(十)参数化User Defined Variables与User Parameters(转载)
转载自 http://www.cnblogs.com/yangxia-test 偶然发现JMeter中有两个元件(User Defined Variables与User Parameters)很相近, ...
- 8 种 NoSQL 数据库系统对比(转自: http://blog.jobbole.com/1344/)
导读:Kristóf Kovács 是一位软件架构师和咨询顾问,他最近发布了一片对比各种类型NoSQL数据库的文章. 虽然SQL数据库是非常有用的工具,但经历了15年的一支独秀之后垄断即将被打破.这只 ...
- php中in_array一些问题
var_dump(in_array(1,['s','1fsdf',12])); // true var_dump(in_array(0,[4,'erdd'])); // true 因为是要用值与数组 ...
- centos 7 搭建openvpn-2.4.6
参考:https://blog.csdn.net/weixin_42250094/article/details/80384863 http://www.startupcto.com/server-t ...
- df.dropna()函数和df.ix(),df.at(),df.loc()