【发布时间】:2010-07-16 00:10:51
【问题描述】:
这可能是一个非常简单的答案,但我似乎无法找到答案,我的目标是 android 2.1。
任何帮助都会很棒:-)
【问题讨论】:
这可能是一个非常简单的答案,但我似乎无法找到答案,我的目标是 android 2.1。
任何帮助都会很棒:-)
【问题讨论】:
在您的 Activity 或其他应用程序组件中试试这个:
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(People.CONTENT_URI, null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String name = formatName(cur.getString(cur
.getColumnIndex(People.DISPLAY_NAME)));
// Do something with name.
}
}
【讨论】:
First you have to add `ListView` in your layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
现在在您的Activity 中使用此代码:
Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
c,
new String[] {People.NAME} ,
new int[] {android.R.id.text1});
setListAdapter(adapter);
【讨论】: