我正在尝试让 ListView 工作,但我在屏幕上收到一条消息,需要关闭应用程序!我正在寻找错误,但我找不到任何错误!也许它在布局内部?我不确定我是否应该在里面有一个 ListView 或者这是创建 cdynamic 的?我究竟做错了什么?我也将使用 onClick 方法,但我想在这种情况下这是一个矿工问题!?一些帮助!谢谢!
public class Activity_3 extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] projection = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};
// Get a cursor with all people
Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, null);
startManagingCursor(cursor);
ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.activity_3, cursor, new String[] {ContactsContract.Contacts.DISPLAY_NAME}, new int[] {R.id.contactItem });
setListAdapter(adapter);
}
}
布局
<?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="vertical" >
<ListView
android:id="@+id/contactList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView android:id="@+id/contactItem" >
</TextView>
</LinearLayout>