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. imp导入数据的时候报错:ORA-01658: 无法为表空间 MAXDATA 中的段创建 INITIAL 区

    在oracle里创建表,报出错: ORA-01658: 无法为表空间space中的段创建 INITIAL 区: 或者: ORA-01658: unable to create INITIAL exte ...

  2. 575. Distribute Candies 平均分糖果,但要求种类最多

    [抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...

  3. keepalived+lvs高可用配置

    global_defs { notification_email { test@qq.com } notification_email_from sns-lvs@gmail.com smtp_serv ...

  4. ubuntu 设置虚拟机和主机在同一网段

    一.在VMware中将网络连接方式设置为桥接 1.打开VM菜单栏->Settings 2.在弹出的Virtual Machine Setting对话框中点击Network Adapter,在右边 ...

  5. jqgrid常用操作

    .jqgrid控件列在需要的地方加上edittable=true <asp:JQGrid runat=" DataUrl="/ccr/CcrCompanyPromoterMa ...

  6. Part4_lesson4---Bootloader架构设计

    1.第一阶段程序设计 第二阶段程序设计

  7. logback.xml 实例

    <?xml version="1.0" encoding="UTF-8"?> <configuration debug="false ...

  8. 如何恢复VS2013代码实时校验功能

      VS2013在某一天突然无法进行实时代码校验了,只有在编译的时候,错误列表才显示语法错误 怎么来解决这个问题呢?试试环境重置吧. 首先:打开工具菜单,选择“导入和导出设置”. 其次:可以先导出选定 ...

  9. Vue Vuex state mutations

    Vuex 解决不同组件的数据共享,与数据持久化 1.npm install vuex --save 2.新建store.js 并引入vue vuex ,Vue.use(Vuex) 3.state在vu ...

  10. Windows中与系统关联自己开发的程序(默认打开方式、图标、右击菜单等)

    1. 默认打开方式 1.1. 代码支持 在Windows下,某个特定后缀名类型的文件,如果要双击时默认用某个程序(比如自己开发的WinForm程序)打开,代码中首先肯定要支持直接根据这个文件进行下一步 ...