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】1018 Big Number
数学题,还是使用log避免大数,但是不要忘记需要+1,因为0也是1位,log(100)= 2,但却是3位. #include <stdio.h> #include <math.h&g ...
- 获取本机的ip
https://4sysops.com/archives/ipv6-tutorial-part-6-site-local-addresses-and-link-local-addresses/ In ...
- bzoj2716
感人肺腑pascal过不去系列(可能是自己弱,因为有pascal过去了毕竟)那个这种平面点还有一种处理方法是kd tree,太弱了不会有时间学一下我还是用了cdq分治,首先肯定要把绝对值这个不和谐的东 ...
- 【转】VS2010/MFC编程入门之二十五(常用控件:组合框控件Combo Box)
原文网址:http://www.jizhuomi.com/software/189.html 上一节鸡啄米讲了列表框控件ListBox的使用,本节主要讲解组合框控件Combo Box.组合框同样相当常 ...
- HTMLPARSER.NET 参考资料
例子1: using System;using System.IO;using Winista.Text.HtmlParser;using Winista.Text.HtmlParser.Lex;us ...
- Extjs4-treepanel-解析json/fields中是否加入leaf的区别
json解析list时,我原先的写法是: Map<String, Object> map = new HashMap<String, Object>(); map.put(&q ...
- STL find() ,还是挺重要的
template<class InputIterator, class T> InputIterator find (InputIterator first, InputIterator ...
- FastCGI技术
1 FastCGI介绍 FastCGI:快速通用网关接口(Fast Common Gateway Interface/FastCGI)是一种让交互程序与Web服务器通信的协议. ...
- 性能测试vs负载测试vs压力测试-概念普及
下面我们主要介绍性能测试.负载测试和压力测试. 效率作为ISO 9126内部和外部质量的重要质量属性之一,其含义是在规定条件下,相对于所用的资源的数量,软件产品可提供适当性能的能力.资源可能包括其他软 ...
- 动态规划:最长上升子序列(LIS)
转载请注明原文地址:http://www.cnblogs.com/GodA/p/5180560.html 学习动态规划问题(DP问题)中,其中有一个知识点叫最长上升子序列(longest incre ...