08_Android中的SimpleAdapter的使用
1 目的界面
2、编写Android清单文件
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima28.simpleadapterdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.itheima28.simpleadapterdemo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
3 activity_main.xml的文件内容
<RelativeLayout 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" tools:context=".MainActivity" > <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> |
4 listview_item.xml的文件内容
<?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="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:padding="10dip" > <ImageView android:id="@+id/iv_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/f007" /> <TextView android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:text="张三" android:textColor="#FF0000" android:textSize="23sp"/> </LinearLayout> |
5 MainActivity的内容如下:
package com.itheima28.simpleadapterdemo; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView mListView = (ListView) findViewById(R.id.listview); List<Map<String, Object>> data = new ArrayList<Map<String,Object>>(); Map<String, Object> map = new HashMap<String,Object>(); map.put("name", "张三1"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap<String,Object>(); map.put("name", "张三2"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap<String,Object>(); map.put("name", "张三3"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap<String,Object>(); map.put("name", "张三4"); map.put("icon", R.drawable.f007); data.add(map); map = new HashMap<String,Object>(); map.put("name", "张三5"); map.put("icon", R.drawable.f007); data.add(map); SimpleAdapter adapter = new SimpleAdapter( this, //上下文 data, //listView绑定的数据 R.layout.listview_item, //listview的子条目的布局的id new String[]{"name","icon"}, //data数据中的map集合里的key new int[]{R.id.tv_name,R.id.iv_icon}); //resource中的id mListView.setAdapter(adapter); } } |
08_Android中的SimpleAdapter的使用的更多相关文章
- 04 SimpleAdapter
<span style="font-size:18px;">package com.fmyboke; import java.util.ArrayList; impor ...
- Android开发(十四)——SimpleAdapter与自定义控件
ListView中可以使用SimpleAdapter进行数据与视图的绑定,但都是对已有的系统控件的绑定,如果自定义空间直接使用SimpleAdapter绑定,则会报错. 如,使用CircleImage ...
- ListActivity的使用
Android中经常用到列表,ListActivity是实现列表的一种好方法. 使用ListActivity的方法,首先定义布局文件: <?xml version="1.0" ...
- View相关知识学习总结
(一)LayoutInflater原理分析 LayoutInflater主要用于加载布局.通常情况下,加载布局的任务都是在Activity中调用setContentView()方法来完成的,该方法内部 ...
- 打造Android万能上拉下拉刷新框架--XRefreshView(三)
转载请注明出处:http://blog.csdn.net/footballclub/ 打造Android万能上拉下拉刷新框架–XRefreshView(一) 打造Android万能上拉下拉刷新框架–X ...
- 安卓第四次作业——简单校园二手交易APP
一.项目团队 团队成员 姓名:汤文涛 学号:1600802129 班级:计算机164班 博客地址:https://www.cnblogs.com/taotao01/ 姓名:杨圣豪 学号:1600802 ...
- Python开源框架
info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...
- Android应用项目中BaseAdapter、SimpleAdapter和ArrayAdapter中的三种适配器
一.写在前面: 本次我们来讲解一下Android应用中三个适配器:BaseAdapter.SimpleAdapter和ArrayAdapter.其中常见的是BaseAdapter,也是个人推荐使用的适 ...
- XML文件解析并利用SimpleAdapter将解析结果显示在Activity中
首先创建一个实体类 Mp3Info用来存储解析的XML文件中的内容: public class Mp3Info implements Serializable{ private static fina ...
随机推荐
- 剑指架构师系列-spring boot的logback日志记录
Spring Boot集成了Logback日志系统. Logback的核心对象主要有3个:Logger.Appender.Layout 1.Logback Logger:日志的记录器 主要用于存放日志 ...
- MongoDB 关系
MongoDB 的关系表示多个文档之间在逻辑上的相互联系. 文档间可以通过嵌入和引用来建立联系. MongoDB 中的关系可以是: 1:1 (1对1) 1: N (1对多) N: 1 (多对1) N: ...
- IDEA中Git的使用
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...
- Git幕后的“故事”
因为做操作系统实验的原因,所以通读了一遍<Understanding git conceptually>,觉得确实不错,于是就简单地记录一下.有的地方理解的还不是很深,可能不够准确,等抽时 ...
- DrawerLayout案例
布局文件: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget ...
- Android Studio 中设置代码块自动补齐
AS中很多提示键,并不如Eclipse中做的好,需要我们自己去自定义.这里以switch...case为例,讲解一下如何设置代码自动补全. 1.进入settings --> Editor -- ...
- ROS机器人程序设计(原书第2版)补充资料 (贰) 第二章 ROS系统架构及概念
ROS机器人程序设计(原书第2版)补充资料 (贰) 第二章 ROS系统架构及概念 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. 由于工作事 ...
- OpenCV, MatBGR2ARGB, ARGB2MatBGR
代码片段~ unsigned int* abMatBGR2ARGB(Mat imag) { int nCols; int nRows; unsigned int *pbuff = NULL; if(i ...
- java的properties文件-jdbc优化编程(五)
通过配置文件能够减小我们的工作量,带来方便. 建立properties文件 1.首先是新建一个dbconfig.properties.然后添加如下代码: driver=com.mysql.jdbc.D ...
- 海量并发的无锁编程 (lock free programming)
最近在做在线架构的实现,在线架构和离线架构近线架构最大的区别是服务质量(SLA,Service Level Agreement,SLA 99.99代表10K的请求最多一次失败或者超时)和延时.而离线架 ...