Android之SimpleAdapter简单实例和SimpleAdapter参数说明
SimpleAdapter基本上认知了其参数含义 用起来就简单多了
SimpleAdapter的参数说明
第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要
第二个参数表示生成一个Map(String ,Object)列表选项
第三个参数表示界面布局的id 表示该文件作为列表项的组件
第四个参数表示该Map对象的哪些key对应value来生成列表项
第五个参数表示来填充的组件 Map对象key对应的资源一依次填充组件 顺序有对应关系
注意的是map对象可以key可以找不到 但组件的必须要有资源填充 因为 找不到key也会返回null 其实就相当于给了一个null资源
下面的程序中如果 new String[] { "name", "head", "desc","name" } new int[] {R.id.name,R.id.head,R.id.desc,R.id.head}
这个head的组件会被name资源覆盖
代码
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- tools:context=".MainActivity" >
- <ListView
- android:id="@+id/lt1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
- </ListView>
- </LinearLayout>
- <?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" >
- <ImageView
- android:id="@+id/head"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingLeft="10dp" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="20dp"
- android:textColor="#f0f"
- android:paddingLeft="10dp"/>
- <TextView
- android:id="@+id/desc"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="14dp"
- android:paddingLeft="10dp"/>
- </LinearLayout>
- </LinearLayout>
- package com.example.simpleadptertest;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- public class MainActivity extends Activity {
- private String[] name = { "剑萧舞蝶", "张三", "hello", "诗情画意" };
- private String[] desc = { "魔域玩家", "百家执行", "高级的富一代", "妹子请过来..一个善于跑妹子的。。" };
- private int[] imageids = { R.drawable.libai, R.drawable.nongyu,
- R.drawable.qingzhao, R.drawable.tiger };
- private ListView lt1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- List<Map<String, Object>> listems = new ArrayList<Map<String, Object>>();
- for (int i = 0; i < name.length; i++) {
- Map<String, Object> listem = new HashMap<String, Object>();
- listem.put("head", imageids[i]);
- listem.put("name", name[i]);
- listem.put("desc", desc[i]);
- listems.add(listem);
- }
- /*SimpleAdapter的参数说明
- * 第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要
- * 第二个参数表示生成一个Map(String ,Object)列表选项
- * 第三个参数表示界面布局的id 表示该文件作为列表项的组件
- * 第四个参数表示该Map对象的哪些key对应value来生成列表项
- * 第五个参数表示来填充的组件 Map对象key对应的资源一依次填充组件 顺序有对应关系
- * 注意的是map对象可以key可以找不到 但组件的必须要有资源填充 因为 找不到key也会返回null 其实就相当于给了一个null资源
- * 下面的程序中如果 new String[] { "name", "head", "desc","name" } new int[] {R.id.name,R.id.head,R.id.desc,R.id.head}
- * 这个head的组件会被name资源覆盖
- * */
- SimpleAdapter simplead = new SimpleAdapter(this, listems,
- R.layout.simple_item, new String[] { "name", "head", "desc" },
- new int[] {R.id.name,R.id.head,R.id.desc});
- lt1=(ListView)findViewById(R.id.lt1);
- lt1.setAdapter(simplead);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
Android之SimpleAdapter简单实例和SimpleAdapter参数说明的更多相关文章
- Android SQLite 的简单实例
1.前言: 今天再一次去蹭了一下某老师的android课,这一次讲的是Android的SQLite的使用,老师当场讲解了他自己做的例子. 回来之后,我春心萌动,不得不拿着参考资料再做了一个类似的例子, ...
- android json 解析简单实例
Android JSON解析跟JAVA 的JSON解析原理是一样的. Android自带的JSON方式跟方便,不需要导包啥的.不深究原理了,直接上代码: public class JsonActivi ...
- Android属性动画-简单实例
1.ValueAnimator //在2000毫秒内,将值从0过渡到1的动画 ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); anim.setD ...
- [Android]RecyclerView的简单演示样例
去年google的IO上就展示了一个新的ListView.它就是RecyclerView. 下面是官方的说明,我英语能力有限,只是我大概这么理解:RecyclerView会比ListView更具有拓展 ...
- 【转】Android Https服务器端和客户端简单实例
转载地址:http://blog.csdn.net/gf771115/article/details/7827233 AndroidHttps服务器端和客户端简单实例 工具介绍 Eclipse3.7 ...
- Android Fragment 简单实例
Android上的界面展示都是通过Activity实现的.Activity实在是太经常使用了.我相信大家都已经很熟悉了,这里就不再赘述. 可是Activity也有它的局限性,相同的界面在手机上显示可能 ...
- android Jni NDK开发环境搭建及其简单实例的编写
android Jni NDK开发环境搭建及其简单实例的编写 由于工作需要,需要采用开发想要的JNI,由于之前没有接触过安卓的开发,所以更加网上的帖子,学习了下.遇到了些问题,然后总结下学习过程中 ...
- Android:PopupWindow简单弹窗改进版
Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...
- appium+robotframework的简单实例
在上篇文章中,我们搭建好了appium+robotframework的环境,这篇文章中主要是一个简单实例. 一.测试用例编写前提 1.模拟器(或手机)连接电脑 adb devices ...
随机推荐
- 星星泡饭-R1SE
作词 : 吴孤儿 时光不用斟酌 再流淌 摩天轮慢慢地旋转 约定 留下搅拌的星光 赵磊: 媲美哪颗星星的孤寂 是我们 脏不了的心 勇敢 游戏 品尝着很饿的梦境 我的梦想只是梦想 哪怕回音只是气球碰撞 会 ...
- 初次在cmd使用git命令上传项目至github方法(笔记)
在一切开始之前,先推荐一个git简易工具书--Git_Cheat_Sheet,非常适合新手.自行搜索即可,也有热心者提供了中文版. 一.下载 Git 从Git官网下载Git安装包 https://gi ...
- DispatcherServlet的url-pattern尽量不要配置为"/*"
DispatcherServlet的url-pattern尽量不要配置为"/*" 原因 当Dispatcher的url配置为"/*"时,会把tomcat的web ...
- Django 多表、跨表、聚合、分组查询
前期准备: 创建表 class Book(models.Model): title = models.CharField(max_length=32) price = models.DecimalFi ...
- mysql报错1548-Cannot load from mysql.proc. The table is probably corrupted
我的版本是5.5.53, 进入到MYSQL-front后,一点击localhost就报错 网上的例子都是说使用mysql_upgrade更新 但是我的是在phpstudy里的mysql,并没有mysq ...
- Salesforce LWC学习(十一) port 1717报错的处理
使用vs code开发lwc的步骤,通常为先创建项目(create project)然后授权一个org(authorize an org),授权以后我们通常便会download代码到本地或者Uploa ...
- 小白学 Python 爬虫(41):爬虫框架 Scrapy 入门基础(八)对接 Splash 实战
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- python字典的遍历
遍历字典: keys() .values() .items() 1. xxx.keys() : 返回字典的所有的key 返回一个序列,序列中保存有字典的所有的键 效果图: 代码: ...
- window10配置python虚拟环境的路径
当我们搭建python+django项目的时候,需要配置虚拟环境,从而使项目与项目之间的包相互隔离,互不影响. 1.配置虚拟环境前,首先需要安装两个包 pip install virtualenvwr ...
- threding.local
作用:为每一个线程开辟一个独立的内存空间 示例 from threading import Thread, local import time obj = local() def test(i): o ...
