WEB开发网
开发学院手机开发Android 开发 android ListView详解 阅读

android ListView详解

 2010-08-23 01:15:00 来源:WEB开发网   
核心提示:004 */005public class MyListView4 extends ListActivity {006007008 private List> mData;009010 @Override011 public void onCreate(Bundle savedInstanceState) {01

004 */

005public class MyListView4 extends ListActivity {

006

007

008 private List> mData;

009

010 @Override

011 public void onCreate(Bundle savedInstanceState) {

012 super.onCreate(savedInstanceState);

013 mData = getData();

014 MyAdapter adapter = new MyAdapter(this);

015 setListAdapter(adapter);

016 }

017

018 private List> getData() {

019 List> list = new ArrayList>();

020

021 Map map = new HashMap();

022 map.put("title", "G1");

023 map.put("info", "google 1");

024 map.put("img", R.drawable.i1);

025 list.add(map);

026

027 map = new HashMap();

028 map.put("title", "G2");

029 map.put("info", "google 2");

030 map.put("img", R.drawable.i2);

031 list.add(map);

032

033 map = new HashMap();

034 map.put("title", "G3");

035 map.put("info", "google 3");

036 map.put("img", R.drawable.i3);

037 list.add(map);

038

039 return list;

040 }

041

042 // ListView 中某项被选中后的逻辑

043 @Override

044 protected void onListItemClick(ListView l, View v, int position, long id) {

045

046 Log.v("MyListView4-click", (String)mData.get(position).get("title"));

047 }

048

049 /**

050 * listview中点击按键弹出对话框

051 */

052 public void showInfo(){

053 new AlertDialog.Builder(this)

054 .setTitle("我的listview")

055 .setMessage("介绍...")

056 .setPositiveButton("确定", new DialogInterface.OnClickListener() {

057 @Override

058 public void onClick(DialogInterface dialog, int which) {

上一页  1 2 3 4 5 6 7 8  下一页

Tags:android ListView 详解

编辑录入:coldstar [复制链接] [打 印]
赞助商链接