我试图让ListView正常工作,但我在屏幕上看到需要关闭应用程序的消息!我正在寻找错误,但我找不到任何!也许它在布局内部?我不知道如果我应该有一个ListView里面或如果这是创建的cdynamic?我究竟做错了什么?我也打算使用onClick方法,但在这种情况下,我猜这是一个矿工问题!?请提供一些帮助!谢谢!ListView强制关闭应用程序
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>
请尝试发布您的DDMS错误日志。打开你的logcat窗口并为你的应用程序添加一个过滤器。然后你可以看到错误。此外你的布局xml似乎不完整。你在用什么IDE? – Timmetje 2013-02-22 12:38:36
其中是Url适配器类,它扩展了SimpleCursorAdapter或baseadapter – saran 2013-02-22 12:47:54
如果您正在扩展List Activity,那么您不需要在布局中放置一个ListView。 – Anukool 2013-02-22 12:48:13