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)的更多相关文章

  1. Android简易实战教程--第十八话《ListView显示,简单的适配器SimpleAdapter》

    本篇介绍Listview的显示,对于listview有许多的适配器,如ArrayAdapter,BaseAdapter,SimpleAdapter等等.本篇先热身一下,介绍最简单的SimpleAdap ...

  2. android 适配器simpleadapter和baseadapter区别

    android 适配器 simpleadapter 和 baseadapter 设计网络程序或者数据处理显示程序的时候,常常会使用 simpleadapter 和baseadapter 来实现. ad ...

  3. Android 数据适配器

    把复杂的数据(数组.链表.数据库.集合等)填充到指定的视图界面上.   arrayAdapter(数组适配器):      用于绑定一些格式单一的数据,数据源:数据或者集合.   private Li ...

  4. [置顶] Android常用适配器控件

    Android常用适配器控件 列表控件用于显示数据集合,Android不是使用一种类型的控件管理显示和数据,而是将这两项功能分布用列表控件和适配器来实现.列表控件扩展了android.widget.A ...

  5. Android简单文件浏览器源代码 (转)

    Android简单文件浏览器源代码 (转) activity_main .xml <LinearLayout xmlns:android="http://schemas.android ...

  6. Android进阶笔记10:Android 万能适配器

    1. Android 万能适配器      项目中Listview GridView几乎是必用的组件,Android也提供一套机制,为这些控件绑定数据,那就是Adapter.用起来虽然还不错,但每次都 ...

  7. Android简单逐帧动画Frame的实现(二)

    Android简单逐帧动画Frame的实现   Android简单逐帧动画Frame的实现 1.逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影. 2.实现步骤: 1. 在工程里 ...

  8. Android进阶笔记09:Android 万能适配器

    1. Android 万能适配器      项目中Listview GridView几乎是必用的组件,Android也提供一套机制,为这些控件绑定数据,那就是Adapter.用起来虽然还不错,但每次都 ...

  9. Android中GridView的使用——使用自带的SimpleAdapter(简单适配器)

    GridView一直是一个系统登录后以九宫格方式展现功能子模块的最佳选择,经过试验和网上资料的查阅,现把实现方式总结一下: 一直是通过自定义Adapter方式,在getView()方法中设置图片的显示 ...

随机推荐

  1. 安装MySQLdb for Python3.7

    Python连接mysql数据库通过MySQLdb模块,在此记录我安装MySQLdb的过程. 一.系统环境 操作系统:Win7 64位 Python:Python 3.7 二.安装说明 A.如果Pyt ...

  2. Extend volumn in ubuntu 14.04

    运行环境: ubuntu 14.04, VMware12.5.7 1. VMware上点击 虚拟机->设置->硬盘(SCSI)->扩展选项,设置自己希望的ubuntu磁盘运行空间大小 ...

  3. 3.SELECT 语句

    SELECT 语句用于从表中选取数据. 结果被存储在一个结果表中(称为结果集). SQL SELECT 语法 SELECT 列名称 FROM 表名称 以及: SELECT * FROM 表名称 注释: ...

  4. python文件复制移动shutil模块

    shutil.copyfile( src, dst) 从源src复制到dst中去.当然前提是目标地址是具备可写权限.抛出的异常信息为IOException. 如果当前的dst已存在的话就会被覆盖掉 s ...

  5. sql修改排序规则,区分大小

    alter   database   数据库   COLLATE   Chinese_PRC_CS_AS     修改排序规则,改成大小写敏感的排序规则     如果只修改一个表,用alter   t ...

  6. (转)MongoDB入门分享-笔记整理精选

    原文地址:http://www.cnblogs.com/Kummy/p/3372729.html 最近在学习MongoDB,怕以后忘记,自己做了一个整理,给不知道的小伙伴一起分享学习一下. 第一步&g ...

  7. delphi 金额大小写转换函数

    {*------------------------------------------------ 金额大小写转换函数 @author 王云盼 @version V1506.01 在delphi7测 ...

  8. C# - dynamic 特性

    dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性. 比如,即使 ...

  9. C# 筛选Datatable、foreach填充DGV,datatable与datarows转换

    public void SelectFG1(string Nane) { string SetText = "卫材代码 like '%" + Nane + "%' or ...

  10. java jeesite.properties配置文件属性提取

    package com.thinkgem.jeesite.common.config; import java.io.UnsupportedEncodingException; import java ...