开发学院手机开发Android 开发 Android 在模拟器上显示数据库中提取的信息的列表... 阅读

Android 在模拟器上显示数据库中提取的信息的列表

 2010-11-05 00:56:33 来源:WEB开发网   
核心提示:SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, data,R.layout.personitem,new String[] { "personid", "name", "age" },

SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, data,

R.layout.personitem,

new String[] { "personid", "name", "age" }, new int[] {

R.id.personid, R.id.name, R.id.age });

listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView< ?> parent, View view,

int position, long id) {

ListView listView = (ListView) parent;

HashMap< String, String> itemData = (HashMap< String, String>) listView

.getItemAtPosition(position);

String personid = itemData.get("personid");

String name = itemData.get("name");

String age = itemData.get("age");

Log.i(TAG, "className" + view.getClass().getName());

// 打印view的类名

Log.i("TAG", "personid=" + personid + ",name=" + name + ",age="

+ age);

Log.i(TAG, "result=" + (position == id));

}

});

}

}

在Layout文件夹下创建personitem.xml的界面配置代码:

< ?xml version="1.0" encoding="utf-8"?>

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content" android:layout_height="wrap_content">

< TextView android:layout_width="60px" android:layout_height="60px"

android:id="@+id/personid" />

< TextView android:layout_width="160px" android:layout_height="wrap_content"

android:layout_toRightOf="@id/personid" android:layout_alignTop="@id/personid"

android:gravity="center_horizontal" android:id="@+id/name" />

< TextView android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_toRightOf="@id/name"

android:layout_alignTop="@id/name" android:id="@+id/age" />

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

Tags:Android 模拟器 显示

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接