android:listview SimpleAdapter
来源:互联网 发布:isodd函数 python 编辑:程序博客网 时间:2024/05/07 16:16
LVActivity.java
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.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.Toast;public class LVActivity extends Activity implements OnItemClickListener{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.list);List<Map<String, String>> l = new ArrayList<Map<String, String>>();Map<String, String> m1 = new HashMap<String, String>();m1.put("name", "zhangsan");m1.put("id", "1");Map<String, String> m2 = new HashMap<String, String>();m2.put("name", "lisi");m2.put("id", "2");Map<String, String> m3 = new HashMap<String, String>();m3.put("name", "wangwu");m3.put("id", "3");l.add(m1);l.add(m2);l.add(m3);ListView lv = (ListView) findViewById(R.id.lv);SimpleAdapter sa = new SimpleAdapter(this, l, R.layout.list_line,new String[] { "name", "id" }, new int[] { R.id.name, R.id.id });lv.setAdapter(sa);lv.setOnItemClickListener(this);}@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {Toast.makeText(this, "you get number id= " + arg3, Toast.LENGTH_SHORT).show();}}
list.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" > <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
list_line.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/name" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="430dp" android:background="#0000aa" android:textSize="30sp" /> <TextView android:id="@+id/id" android:layout_width="200dp" android:layout_height="wrap_content" android:background="#00aa00" android:textSize="30sp" /> </LinearLayout>
- android:listview SimpleAdapter
- Android--ListView和SimpleAdapter
- Android ListView使用SimpleAdapter
- Android基础(六) ListView - SimpleAdapter
- Android SimpleAdapter显示ListView、GridView
- Android SimpleAdapter显示ListView、GridView
- Android入门:ListView(SimpleAdapter实现)
- android listView-simpleadapter(点击事件)
- Android之SimpleAdapter和ListView
- Android SimpleAdapter显示ListView、GridView
- Android入门:ListView(SimpleAdapter实现)
- android的ListView中SimpleAdapter
- Android入门:ListView(SimpleAdapter实现)
- Android SimpleAdapter显示ListView、GridView
- Android SimpleAdapter显示ListView、GridView
- [Android] ListView 结合SimpleAdapter使用
- ListView(SimpleAdapter)
- ListView SimpleAdapter
- 正则表达式
- QT错误:collect2:ld returned 1 exit statu
- selenium 一个操作网页的库
- 中国34省未来发展深度分析
- linux下安装JDK
- android:listview SimpleAdapter
- Android 获取ROOT权限原理解析
- sscanf()函数用法
- 解决ubuntu下硬盘磁头敲击异响
- Exception in BPOfferService for Block pool BP
- Ubuntu12.04 安装eclipse
- XML文件的编码问题
- insmod: error inserting 'simp-blkdev.ko': -1 Invalid module format
- [pig] 统计行数和单词个数wordcount