android ListView 的使用
16lz
2021-01-23
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和PC端通过局域网文件同步
- android 根据apk文件路径获取图标
- Android SD卡文件列表
- AndroidManifest.xml配置文件选项详解
- android--------根据文件路径使用File类获取文件相关信息
- 安卓4.X系统 增加蓝牙接收文件类型
- 用SAX解析xml文件