1. main .xml 配置文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <LinearLayout         android:id="@+id/lausb"        android:orientation="vertical"        android:layout_height="wrap_content"        android:layout_width="wrap_content">        <ListView             android:id="@android:id/list"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:drawSelectorOnTop="false"            android:scrollbars="vertical"            ></ListView>    </LinearLayout></LinearLayout>

2. user.xml 配置文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="horizontal" >    <TextView            android:id="@+id/title"           android:layout_width="wrap_content"           android:layout_height="fill_parent"           android:textSize="22px"            android:width="100px"            />    <TextView        android:id="@+id/info"       android:layout_width="wrap_content"       android:layout_height="fill_parent"        /></LinearLayout>

3. java 类文件

package com.listview;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;import android.app.ListActivity;import android.os.Bundle;import android.view.View;import android.widget.ListView;import android.widget.SimpleAdapter;/** *  * @author liuqing * @version 1.0 * @see Android ListView 的使用 * 2011-10-12 * */public class ListViewActius extends ListActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.main);ArrayList<Map<String,String>> list = new ArrayList<Map<String,String>>();Map<String,String> map1 = new HashMap<String,String>();Map<String,String> map2 = new HashMap<String,String>();Map<String,String> map3 = new HashMap<String,String>();map1.put("title", "liuqing");map1.put("info", "192.168.0.105");map2.put("title", "qing");map2.put("info", "192.168.32");map3.put("title", "haha");map3.put("info", "192.168.0.22");list.add(map1);list.add(map2);list.add(map3);SimpleAdapter listAdapter = new SimpleAdapter(this,list,R.layout.user,new String[]{"title","info"},new int[]{R.id.title,R.id.info});setListAdapter(listAdapter);}@Overrideprotected void onListItemClick(ListView l, View v, int position, long id) {super.onListItemClick(l, v, position, id);System.out.println(" position:" + position + "===id: " + id);}}
android ListView 的使用

更多相关文章

  1. Android和PC端通过局域网文件同步
  2. android 根据apk文件路径获取图标
  3. Android SD卡文件列表
  4. AndroidManifest.xml配置文件选项详解
  5. android--------根据文件路径使用File类获取文件相关信息
  6. 安卓4.X系统 增加蓝牙接收文件类型
  7. 用SAX解析xml文件

随机推荐

  1. Android -- android app 能分配的最大内
  2. Android Content Provider[转]
  3. android中的LayoutInflater
  4. Android之Android studio动态搜索添加依
  5. 《Android》Lesson19-广播1
  6. Android之常用开发框架
  7. Android项目中使用MVP模式
  8. Android studio 自定义打包APK名称
  9. Android中ActivityManager学习笔记(3)
  10. Android学习笔记-1.Android工程结构