Android 简单适配器(SimpleAdapter)
1.介绍

2.简单适配器的实现方法

3.XML文件
(1)主页面布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> <ListView
android:id="@+id/listview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"> </ListView> </LinearLayout>
(2)子项布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" /> <ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@mipmap/img01" />
</LinearLayout>
4.java后台
package com.lucky.test29simpleadapter; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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 MainActivity extends AppCompatActivity { ListView listView; //列表视图
SimpleAdapter simpleAdapter; //简单适配器可以将图片和文件组合起来
List<Map<String,Object>> list1;
//Android studio工程将图片转变为的数字
int[] images={R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,R.mipmap.img05,R.mipmap.img06,R.mipmap.img07,R.mipmap.img08};
String[] contentstr={"虎扑","头条","QQ","微信","百度","起点","美团","滴滴"}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=findViewById(R.id.listview1);
list1=new ArrayList<>(); //实例化list1
for (int i = 0; i <images.length ; i++) {
Map<String,Object> map=new HashMap<>(); //实例化map
map.put("001",images[i]); //给map添加值,参数1为代号,参数2为数据值
map.put("002",contentstr[i]);
list1.add(map);
}
//实例化simpleAdapter,并设置参数,参数2为数据,参数3为子项的布局文件,参数4为数据的代号,参数5为组件的id
simpleAdapter=new SimpleAdapter(MainActivity.this,list1,R.layout.itemsimple,new String[]{"001","002"},new int[]{R.id.imageView,R.id.textView});
listView.setAdapter(simpleAdapter); //设置适配器 }
}
5.效果图

Android 简单适配器(SimpleAdapter)的更多相关文章
- Android简易实战教程--第十八话《ListView显示,简单的适配器SimpleAdapter》
本篇介绍Listview的显示,对于listview有许多的适配器,如ArrayAdapter,BaseAdapter,SimpleAdapter等等.本篇先热身一下,介绍最简单的SimpleAdap ...
- android 适配器simpleadapter和baseadapter区别
android 适配器 simpleadapter 和 baseadapter 设计网络程序或者数据处理显示程序的时候,常常会使用 simpleadapter 和baseadapter 来实现. ad ...
- Android 数据适配器
把复杂的数据(数组.链表.数据库.集合等)填充到指定的视图界面上. arrayAdapter(数组适配器): 用于绑定一些格式单一的数据,数据源:数据或者集合. private Li ...
- [置顶] Android常用适配器控件
Android常用适配器控件 列表控件用于显示数据集合,Android不是使用一种类型的控件管理显示和数据,而是将这两项功能分布用列表控件和适配器来实现.列表控件扩展了android.widget.A ...
- Android简单文件浏览器源代码 (转)
Android简单文件浏览器源代码 (转) activity_main .xml <LinearLayout xmlns:android="http://schemas.android ...
- Android进阶笔记10:Android 万能适配器
1. Android 万能适配器 项目中Listview GridView几乎是必用的组件,Android也提供一套机制,为这些控件绑定数据,那就是Adapter.用起来虽然还不错,但每次都 ...
- Android简单逐帧动画Frame的实现(二)
Android简单逐帧动画Frame的实现 Android简单逐帧动画Frame的实现 1.逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影. 2.实现步骤: 1. 在工程里 ...
- Android进阶笔记09:Android 万能适配器
1. Android 万能适配器 项目中Listview GridView几乎是必用的组件,Android也提供一套机制,为这些控件绑定数据,那就是Adapter.用起来虽然还不错,但每次都 ...
- Android中GridView的使用——使用自带的SimpleAdapter(简单适配器)
GridView一直是一个系统登录后以九宫格方式展现功能子模块的最佳选择,经过试验和网上资料的查阅,现把实现方式总结一下: 一直是通过自定义Adapter方式,在getView()方法中设置图片的显示 ...
随机推荐
- 170318 11:44:26 [ERROR] Can't start server: can't create PID file: No space left on device
数据库挂了.打开远程,进了系统,service mysqld stop 失败.service mysqld start等了好大一会,提示Timeout error occurred trying to ...
- Spring中使用Velocity模板
使用Velocity模板 Velocity是一种针对Java应用的易用的模板语言.Velocity模板中没有任何 Java代码,这使得它能够同时被非开发人员和开发人员轻松地理解.Velocity的用户 ...
- 面试题:SSH项目总结 !=!=未看 没用
阿玻罗软件(上海)有限公司已经两年了.中国银行营销系统,到民生银行小微信贷工厂建设.再到交通银行ioffice移动平台项目.以前所学的SSH好多都用不上 公司的框架.都是负责项目的贷款查找模块开发和测 ...
- jQuery--基础知识速查表
一.jQuery选择器 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" 的 ...
- Java设计模式(1)——简单工厂模式
简单工厂模式属于类的创建型模式,又叫做静态工厂方法模式.通过专门定义一个类来负责创建其他类的实例,被创建的实例通常都具有共同的父类. 一.模式中包含的角色及其职责 1.工厂(Creator)角色 简单 ...
- 黑盒测试实践--Day3 11.27
黑盒测试实践--Day3 今天完成任务情况: 收到小组紧急通知,作业要求更新了.组长召集大家在下午课后去开个短会,会议信息如下: 时间:11.27 晚上5:30 地点:东九楼501 会议内容: 学习了 ...
- [GO]猜数字的小游戏
随机生成四位数字,然后用户输入四位数字,然后根据提示一步步猜到随机数 package main import ( "math/rand" "time" &quo ...
- Python基础入门-os模块
今天我们来介绍一下os模块中常用的一些方法,当然python中的os模块中提供的使用方法有很多,但是这里面小编会列举出来一些和实际工作中应用的相关的方法,而且会有一些实际的例子方便大家对os模块理解. ...
- backquote
character (`) A backquote or backtick. echo 'date' date echo `date` 2015年 07月 03日 星期五 16:11:13 CST j ...
- jstl c
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 例子:list中有两 ...