Android 在模拟器上显示数据库中提取的信息的列表
2010-11-05 00:56:33 来源:WEB开发网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"
更多精彩
赞助商链接