ListView控件:(2)SimpleAdapter适配器生成
来源:互联网 发布:手机棋牌软件开发 编辑:程序博客网 时间:2024/05/16 11:19
1.java代码
package com.yun.activity;import java.util.ArrayList;import java.util.HashMap;import com.example.yunsheng.R;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.Toast;public class MySimpleAdapter extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_simpleadapter);ListView lv = (ListView) findViewById(R.id.lv);/* 定义一个动态数组 */ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();/* 在数组中存放数据 */for (int i = 0; i < 10; i++) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("userId", "第" + i + "行");map.put("userName", "这是第" + i + "行");map.put("userImage", R.drawable.ic_ipod);// 加入图片listItem.add(map);}SimpleAdapter mSimpleAdapter = new SimpleAdapter(this, listItem,// 需要绑定的数据R.layout.simpleadapter_item,// 每一行的布局// 动态数组中的数据源的键对应到定义布局的View中new String[] { "userId", "userName", "userImage" }, new int[] {R.id.userId, R.id.userName, R.id.userImage });lv.setAdapter(mSimpleAdapter);// 为ListView绑定适配器lv.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {// TODO Auto-generated method stubsetTitle("你点击了第" + arg2 + "行");// 设置标题栏显示点击的行HashMap item = (HashMap) arg0.getItemAtPosition(arg2);String section = String.valueOf(item.get("userName").toString());// get每一行的数据的名字Toast.makeText(MySimpleAdapter.this, section, Toast.LENGTH_LONG).show();}});}}
2.配置文件
/Yunsheng/res/layout/activity_simpleadapter.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="wrap_content" android:id="@+id/myListItem" android:paddingBottom="3dip" android:paddingLeft="10dip"> <!-- 添加一个ListView控件 --><ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
/Yunsheng/res/layout/simpleadapter_item.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/userId" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="20dp" > </TextView> <TextView android:id="@+id/userName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#F00F11" > </TextView> </LinearLayout> <ImageView android:id="@+id/userImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:rotationX="30" /></RelativeLayout>
3.执行结果
0 0
- ListView控件:(2)SimpleAdapter适配器生成
- ListView控件:(3)BaseAdapter适配器生成
- SimpleAdapter适配器填充ListView
- ListView使用SimpleAdapter适配器
- Android UI设计——ListView控件与SimpleAdapter适配器(三)
- Android 之 ListView列表控件 的SimpleAdapter适配器
- Android UI 设计:ListView 控件与 SimpleAdapter 适配器
- ListView适配器--ArrayAdapter;SimpleAdapter;SimpleCursorAdapter
- ListView控件:(1)ArrayAdapter<T>适配器生成
- Android学习之listView显示下拉列表(2)(SimpleAdapter适配器)
- ListView 的三种适配器 BaseAdapter ArrayAdapter SimpleAdapter(2)
- ListView列表的实现2——SimpleAdapter数组适配器
- ListView实现图文列表(重要) 使用SimpleAdapter适配器
- 【Android学习笔记】ListView使用SimpleAdapter适配器
- 关于ListView使用BaseAdapter和SimpleAdapter适配器
- 【Android】ListView与SimpleAdapter适配器的使用
- ListView (3) 之适配器 ArrayAdapter/SimpleAdapter/BaseAdapter
- android ListView适配器之SimpleAdapter的用法
- 广义表的原子统计
- SIFT算法实现理解及注释详解(基于Rob Hess源码)
- centos7 firewalld配置示例
- hello csdn
- 在VS2010中应用SIFT(C)源码
- ListView控件:(2)SimpleAdapter适配器生成
- android上FragmentTabHost实现自定义Tab Indicator
- 二叉树的深度优先遍历和广度优先遍历
- android 语言设置
- Android:LayoutInflater的inflate方法
- 二叉树算法库
- Linux学习【菜鸟篇】- 学习笔记- 打包压缩解压
- Build nodejs express framework in MACOS
- CSS之transition, transform, tanslate,animation