package com.lidaochen.test;

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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 找到ListView控件
ListView listView = (ListView)findViewById(R.id.lv);
// 准备ListView要显示的数据
List<Map<String, String>> data = new ArrayList<Map<String, String >>();
Map<String, String> map1 = new HashMap<String, String>();
map1.put("name", "张飞");
map1.put("phone", "13688888888");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("name", "马云");
map2.put("phone", "13777777777");
Map<String, String> map3 = new HashMap<String, String>();
map3.put("name", "刘强东");
map3.put("phone", "13222222222");
Map<String, String> map4 = new HashMap<String, String>();
map4.put("name", "马化腾");
map4.put("phone", "13666666666");
// 将map加入到集合中
data.add(map1);
data.add(map2);
data.add(map3);
data.add(map4);
// 创建一个SimpleAdapter
SimpleAdapter simpleAdapter = new SimpleAdapter(this, data, R.layout.item,
new String[]{"name", "phone"}, new int[]{R.id.tv_name, R.id.tv_phone});
// 设置适配器
listView.setAdapter(simpleAdapter);
}
}
<?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="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/tv_name"
android:textSize="20sp"
android:layout_weight="1"
android:textColor="#d20606"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:id="@+id/tv_phone"
android:layout_weight="1"/> </LinearLayout>

安卓开发之SimpleAdapter的使用的更多相关文章

  1. 安卓开发之ListAdapter(二)

    今天我们来学习一下ArrayAdapter: ArrayAdapter是安卓中最简单的适配器.使用ArrayAdapter(数组适配器),需要把数据源存 放至数组里面来显示. •构造函数: publi ...

  2. 安卓开发之Toolbar

    根据官网的教程,发现实现与预期不一致,查看相关资料自己整理了一下(官网开发文档:https://developer.android.com/training/appbar/setting-up.htm ...

  3. 安卓开发之ListAdapter(一)

    Adapter常用来管理数据,是连接后端数据和前端显示的适配器接口,是数据和UI(view)之间一个重要的纽带.再常见的view(listview.gridview)等地方都需要用到adapter,下 ...

  4. 安卓开发之UIwebview

    web view在安卓开发中是比较常见的UI,像微信的新闻模块就采用了这个,他的作用越来越广,下面我把以前做的贴了出来,如果有更好的办法,希望大神不吝赐教哈,嘿嘿,纯代码来了: java代码 publ ...

  5. 安卓开发之activity详解(sumzom)

    app中,一个activity通常是指的一个单独的屏幕,相当于网站里面的一个网页,它是对用户可见的,它上面可以显示一些控件,并且可以监听处理用户的时间做出响应. 那么activity之间如何进行通信呢 ...

  6. 安卓开发之json解析

    1.从网页获取json返回字符串 public class ReadNet extends AsyncTask<URL, Integer, String> { @Override      ...

  7. 安卓开发之viewpager学习(头条显示)

    activity_luancher.xml代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res ...

  8. 安卓开发之RecyclerView

    RecyclerView是一个非常好用的控件,它的效果和ListView很相似,甚至可以说RecyclerView的出现是来取代ListView的 RecyclerView比ListView更加灵活, ...

  9. 安卓开发之APK安装之后自动在桌面上创建快捷图标

    可以看到很多的APP在第一次运行之后就会弹出来一个Toast说什么快捷方式已创建,那么这个东西是怎么搞出来的呢 很简单就下面几句话,写在这儿以后好copy 先创建一个类 import android. ...

随机推荐

  1. linux高可用集群(HA)原理详解

    高可用集群 一.什么是高可用集群 高可用集群就是当某一个节点或服务器发生故障时,另一个节点能够自动且立即向外提供服务,即将有故障节点上的资源转移到另一个节点上去,这样另一个节点有了资源既可以向外提供服 ...

  2. JDBC获得DB2表结构并且将表中数据脱敏后转移的程序示例

    完整项目地址:https://github.com/zifeiy/totomi 代码示例: import java.io.File; import java.io.FileInputStream; i ...

  3. Ubuntu 16.04安装MySQL设置远程访问出现问题的完美解决方案(error:10061)

    一.安装mysql 安装mysql过程中,需要设置mysql的root账号的密码,不要忽略了. sudo apt-get install mysql-server apt isntall mysql- ...

  4. Jmeter 逻辑控制器 之 Include Controller

    一.认识 Include Controller Include Controller :译为包含控制器,用来添加 Test Fragment(测试片段).具体是什么意思呢,我们先来了解下 Test F ...

  5. 【极简版】OpenGL 超级宝典(第五版)环境配置 VS2010

    事先声明:该教程仅适用于VS2010环境下超级宝典第五版的配置 第一步:下载示例代码和环境包: 链接:https://pan.baidu.com/s/1llRRQ8ymBgMGuXp5M50pJw 提 ...

  6. RestHighLevelClient 之 Scroll

    ES中默认最大查询结果为10000,大于10000时查不出结果,报错超过最大值,如把 from调到大于10000. 针对这个问题,有两种解决办法. 第一种,修改 max_result_window 很 ...

  7. eduSOHO 首页模板 全部课程模块代码

    首页模板文件 设置在后台主题-管理-选中网校课程 然后前台调用代码 {% if code != 'course-grid-with-condition-index' %}        {% cach ...

  8. 后端根据查询条件生成excel文件返回给前端,vue进行下载

    一.HTML代码 <el-col :xs="2" :md="2" :sm="3"> <el-button type=&qu ...

  9. redis设置密码和其它服务器连接

    在cenos中 vim /etc/redis.conf 中 /输入 requirepass enter件一下 小写 n 一下 吧 # requirepass #去掉,后面写你的密码 #其它机器连接 v ...

  10. Mac/Windows 跳过sourcetree的注册环节

      前几天在电脑上装了个sourcetree,结果它硬要我注册,烦得很.   于是查了一下怎么跳过注册环节,结果还真有,试了一下,真给力!   特此记录. MAC版本: 打开sourcetree 关闭 ...