Android_listView_exc
listView布局:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.homework04.MainActivity" > <ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </RelativeLayout>
item布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- 图像 -->
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/image1"
/>
<!-- 姓名 -->
<TextView
android:id="@+id/text_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:text="名侦探柯南"/>
<!-- 年龄 -->
<TextView
android:id="@+id/text_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:layout_alignBottom="@id/image"
android:textSize="20sp"
android:layout_marginBottom="10dp"
android:text="17"/>
<!-- 按钮 -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_toRightOf="@id/text_name"
android:layout_marginTop="25dp"
android:text="更多"
/>
</RelativeLayout>
源代码:
package com.example.homework04; 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.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleAdapter; public class MainActivity extends Activity {
private ListView listview;
private SimpleAdapter adapter; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化adapter
adapter = new SimpleAdapter(
MainActivity.this, // 第一个参数:上下文
getData(),// 第二个参数:listview中显示的数据
R.layout.item,// 第三个参数:每行的布局
new String[]{"image", "name", "age", "button"},// 第四个参数:字符串数组 Map中的key的值
new int[]{R.id.image, R.id.text_name, R.id.text_age, R.id.button}); // 第五个参数:item.xml中每个控件的id
listview = (ListView) findViewById(R.id.listview);
listview.setAdapter(adapter);
} // 生成listview显示的数据
private List<Map<String, ?>> getData() {
// TODO Auto-generated method stub
List<Map<String,?>> list = new ArrayList<Map<String,?>>();
int[] image = {R.drawable.image1,R.drawable.image2,R.drawable.image3};
String[] name={"野比大雄","野比先生","野比太太"};
String[] age={"12","40","38"};
for (int i = 0; i < age.length; i++) {
Map<String,Object> map = new HashMap<String, Object>();
map.put("image", image[i]);
map.put("text_name", name[i] );
map.put("text_age", age[i] );
map.put("button", "更多");
list.add(map);
}
return list;
}
}

Android_listView_exc的更多相关文章
随机推荐
- 【HDOJ】4267 A Simple Problem with Integers
树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...
- 去除浏览器下jquey easyui datagrid、combotree 缓存问题
在页面脚本中加入以下内容即可: $.ajaxSetup ({ cache: false //关闭AJAX相应的缓存 });
- java含多个包的命令行下执行
C:\Users\liyang\Desktop\BAE\Baidu-BCS-SDK-Java-1.4.5>java -classpath(可以cp简写) bcs-sdk-java_1.4.5.j ...
- libcurl断点下载
开发需要写了一个处理curl 下载的c++类,内含有多个静态方法和实例方法,写在这里留给有需求的同学 头文件 CURLHelper.h enum CURLHelperStateType { CURLH ...
- javaweb之javascript结合(三)
1.案例一:在末尾添加节点 第一步:获取到ul标签 第二步:创建li标签 document.createElement("标签名称")方法 第三步:创建文本 document.cr ...
- bzoj 1951 [Sdoi2010]古代猪文(数论知识)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1951 [思路] 一道优(e)秀(xin)的数论题. 首先我们要求的是(G^sigma{ ...
- phpMyAdmin安装设置
phpMyAdmin是一种MySQL的管理工具,它直接从web上去管理MySQL. 假设你的web(网页存放)根目录是 /var/www/ 假设你的主机web访问是这样的 http://192.1 ...
- cocos2d-x 从onEnter、onExit、 引用计数 谈内存泄露问题
/////////////////////////////////// //author : zhxfl //date : 2013.8.29 //email : 291221622@qq.co ...
- CF_402C Searching for Graph 乱搞题
题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...
- weblogic启动时日志重定向(nohup.out)
由于weblogic使用 nohup ./startWebLogic.sh & 启动时会将所有日志打印到nohup.out上,长此以往会导致该文件越来越大,不便于管理. 故下面介绍如何重 ...