安卓开发之SimpleAdapter的使用
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的使用的更多相关文章
- 安卓开发之ListAdapter(二)
今天我们来学习一下ArrayAdapter: ArrayAdapter是安卓中最简单的适配器.使用ArrayAdapter(数组适配器),需要把数据源存 放至数组里面来显示. •构造函数: publi ...
- 安卓开发之Toolbar
根据官网的教程,发现实现与预期不一致,查看相关资料自己整理了一下(官网开发文档:https://developer.android.com/training/appbar/setting-up.htm ...
- 安卓开发之ListAdapter(一)
Adapter常用来管理数据,是连接后端数据和前端显示的适配器接口,是数据和UI(view)之间一个重要的纽带.再常见的view(listview.gridview)等地方都需要用到adapter,下 ...
- 安卓开发之UIwebview
web view在安卓开发中是比较常见的UI,像微信的新闻模块就采用了这个,他的作用越来越广,下面我把以前做的贴了出来,如果有更好的办法,希望大神不吝赐教哈,嘿嘿,纯代码来了: java代码 publ ...
- 安卓开发之activity详解(sumzom)
app中,一个activity通常是指的一个单独的屏幕,相当于网站里面的一个网页,它是对用户可见的,它上面可以显示一些控件,并且可以监听处理用户的时间做出响应. 那么activity之间如何进行通信呢 ...
- 安卓开发之json解析
1.从网页获取json返回字符串 public class ReadNet extends AsyncTask<URL, Integer, String> { @Override ...
- 安卓开发之viewpager学习(头条显示)
activity_luancher.xml代码如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res ...
- 安卓开发之RecyclerView
RecyclerView是一个非常好用的控件,它的效果和ListView很相似,甚至可以说RecyclerView的出现是来取代ListView的 RecyclerView比ListView更加灵活, ...
- 安卓开发之APK安装之后自动在桌面上创建快捷图标
可以看到很多的APP在第一次运行之后就会弹出来一个Toast说什么快捷方式已创建,那么这个东西是怎么搞出来的呢 很简单就下面几句话,写在这儿以后好copy 先创建一个类 import android. ...
随机推荐
- 阿里云服务器怎么用ip访问不了
个人想做个网站,就买了个阿里云服务器,不得不说阿里的安全做的很好,但是对于我这种小白,就成了麻烦了 工具/原料 阿里云服务器 方法/步骤 首先百度搜索阿里云,进入登录界面,输入账号密码登录 ...
- Method org/apache/commons/dbcp/DelegatingResultSet.isClosed()Z is abstract
按照网络上的排除建议,换成了alibaba的druid. 相关maven依赖如下,注意版本匹配问题 spring版本使用4.3.24.RELEASE <dependency> <gr ...
- LeetCode_14. Longest Common Prefix
14. Longest Common Prefix Easy Write a function to find the longest common prefix string amongst an ...
- JAVA 基础编程练习题30 【程序 30 插入数字】
30 [程序 30 插入数字] 题目:有一个已经排好序的数组.现输入一个数,要求按原来的规律将它插入数组中. 程序分析:首先判断此数是否大于最后一个数,然后再考虑插入中间的数的情况,插入后此元素之后的 ...
- TFTP反射放大攻击浅析
0x00 前言 经由@杀戮提示,让我看看softpedia上的这篇报道,咱就来研究一下文中的使用TFTP(Trivial File Transfer Protocol,简单文件传输协议)进行反射型DD ...
- es6 是否包含字符串判断
字符串查找类 接下来介绍一些可以通过 ES5 PolyFill的方法,但是现在 ES6 原生实现了 Method Param Return Description includes() 需要验证是否被 ...
- Spring Aop(十三)——ProxyFactoryBean创建代理对象
转发地址:https://www.iteye.com/blog/elim-2398673 ProxyFactoryBean创建代理对象 ProxyFactoryBean实现了Spring的Factor ...
- HashMap和ConcurrentHashMap 源码关键点解析
第一部分:关键源码讲解 1.HashMap 是如何存储的? a.底层是一个数组 tab b. hash=hash(key) ,然后根据数组长度n和hash值,决定当前需要put的元素对应的数组下标, ...
- 日记 进程 ip /端口
查看日记: tail -f log.txt 循环查看 cat info 查看文件 less info 查看文件 head -n 10 /vv/v ...
- 【ABAP系列】SAP ABAP Break Point
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP Break P ...