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. apt如何列出所有已经安装的软件包

    apt如何列出所有已经安装的软件包 转 https://www.helplib.com/ubuntu/article_155294 问题: 我想将所有已安装软件包的列表输出到文本文件中,以便我可以查看 ...

  2. exactly the kind of division of tasks that Gulp.js is built on

    The results are then passed to a reporter function that displays the results of the code analysis in ...

  3. SpringBoot学习之一 Unable to find a single main class from the following candidates

    在启动SpringBoot项目是报错 Unable to find a single main class from the following candidates [boot.myboot.Sam ...

  4. sed例子

    以care.log这个log文件为例, care.log: 05:44:31,816 DEBUG RawAggregationWorker:70 - LTS is working on Raw Dat ...

  5. python基础----条件判断与循环

    一.python数据类型 1.整数(包括整数.负数) 2.浮点数(小数) 3.字符串(需要用单引号‘’或双引号“”括起来) 注:当字符串中含有单引号时,用双引号括起来(now="let's ...

  6. 二分类Logistic回归模型

    Logistic回归属于概率型的非线性回归,分为二分类和多分类的回归模型.这里只讲二分类. 对于二分类的Logistic回归,因变量y只有“是.否”两个取值,记为1和0.这种值为0/1的二值品质型变量 ...

  7. Galileo:一款开源Web应用审计框架

    转载自FreeBuf.COM Galileo是一款针对Web应用程序的开源渗透测试工具,可帮助开发和渗透测试人员识别并利用其Web应用程序中的漏洞. 截图 安装 $ git clone https:/ ...

  8. tf.contrib.rnn.LSTMCell 里面参数的意义

    num_units:LSTM cell中的单元数量,即隐藏层神经元数量.use_peepholes:布尔类型,设置为True则能够使用peephole连接cell_clip:可选参数,float类型, ...

  9. vue学习中遇到的问题

    1.axios使用post传值时无法使用键值对传值的问题 问题的原因:主要是HTTP请求中的get请求和post请求参数的存放位置是不一样的,get请求的参数以键值对的方式跟在url后面的,而post ...

  10. 计算1-9总共九个数字可以满足abc+def=hij这样的式子

    计算1-9总共九个数字可以满足abc+def=hij这样的式子:其中abcdefghij九个数字各个都不相同,它们都属于1-9个数字中: 首先,第一种方法很简单很暴力,直接枚举,这样的话时间复杂度高: ...