SimpleCursorAdapter期望什么样的xml?

时间:2012-01-08 15:27:08

标签: android android-layout android-contacts android-activity android-alertdialog

我一直遇到在AlertDialog中显示联系人的问题,我想我已经找到了 问题,但我仍然困惑。我的代码中相关的可疑部分是:

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
        android.R.layout.simple_list_item_1, mContacts,
        new String[] { ContactsContract.Contacts.DISPLAY_NAME },
        new int[] { android.R.id.text1 });

...现在编译器接受“simple_list_item_1”(应用程序在模拟器中运行),但是 我尝试运行这个ListActivity,它就是炸弹。

因此,在读完其他地方关于如何完成这项任务之后,我的目光点亮了前面所说的 “simple_list_item_1” - 这是哪里?我没有创建任何simple_list_item_1.xml文件,它在我的\ res \ layout文件夹中不存在。所以我(在Eclipse中)右键单击“simple_list_item_1”并选择“Open Declaration”,它调用了一个错误的msg,或者与我在Debug Perspective中看到的关于“Class File Editor | Source nout found | JAR file”的错误信息完全相同。 ... \ android.jar没有源附件。“

所以......假设这是问题(我的\ res \ layout文件夹中没有“simple_list_item_1.xml”),这个文件到底是什么(我假设它只是我想要的xml定义)每个联系人显示在?)

==============

以下是一些LogCat数据:

以下是LogCat中的最后几行(一旦到达ListActivity(ContactsActivity),它似乎就会死掉/挂起:

com.aXX3AndSpace.KeepInTouch/.KeepInTouchActivity: +5s368ms
01-08 21:54:34.020: I/ActivityManager(61): Starting: Intent { cmp=com.aXX3AndSpace.KeepInTouch/.ContactsActivity } from pid 385

...以下是一次尝试运行中的所有错误消息(打开应用程序,尝试调用ListActivity)。请注意“应该永远不会发生”msg:

01-08 21:53:36.592: E/Zygote(33): setreuid() failed. errno: 2
01-08 21:53:46.423: E/Zygote(33): setreuid() failed. errno: 17
01-08 21:53:47.842: E/BatteryService(61): usbOnlinePath not found
01-08 21:53:47.842: E/BatteryService(61): batteryVoltagePath not found
01-08 21:53:47.842: E/BatteryService(61): batteryTemperaturePath not found
01-08 21:53:47.862: E/SurfaceFlinger(61): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
01-08 21:53:48.082: E/SensorService(61): couldn't open device for module sensors (Invalid argument)
01-08 21:53:53.722: E/System(61): Failure starting core service
01-08 21:53:53.722: E/System(61): java.lang.SecurityException
01-08 21:53:53.722: E/System(61):   at android.os.BinderProxy.transact(Native Method)
01-08 21:53:53.722: E/System(61):   at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
01-08 21:53:53.722: E/System(61):   at android.os.ServiceManager.addService(ServiceManager.java:72)
01-08 21:53:53.722: E/System(61):   at com.android.server.ServerThread.run(SystemServer.java:207)
01-08 21:53:53.742: E/EventHub(61): could not get driver version for /dev/input/mouse0, Not a typewriter
01-08 21:53:53.742: E/EventHub(61): could not get driver version for /dev/input/mice, Not a typewriter
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/Effect_Tick.ogg
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/KeypressStandard.ogg
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/KeypressSpacebar.ogg
01-08 21:53:54.042: E/SoundPool(61): error loading /system/media/audio/ui/KeypressDelete.ogg
01-08 21:53:54.042: E/SoundPool(61): error loading /system/media/audio/ui/KeypressReturn.ogg
01-08 21:53:54.703: E/ThrottleService(61): Could not open GPS configuration file /etc/gps.conf
01-08 21:53:57.172: E/logwrapper(158): executing /system/bin/tc failed: No such file or directory
01-08 21:53:57.242: E/logwrapper(159): executing /system/bin/tc failed: No such file or directory
01-08 21:53:57.282: E/logwrapper(160): executing /system/bin/tc failed: No such file or directory
01-08 21:54:00.074: E/jdwp(174): Failed sending reply to debugger: Broken pipe
01-08 21:54:00.712: E/Database(116): sqlite_config failed error_code = 21. THIS SHOULD NEVER occur.

2 个答案:

答案 0 :(得分:2)

simple_list_item_1是SDK中定义的标准布局,它基本上只是一个ID为“android:id / text1”的TextView,这是您在视图标识符中提供的内容。

你有崩溃的堆栈跟踪吗?因为它很可能不是因为缺少simple_list_item_1布局。

答案 1 :(得分:1)

使用Eclipse向导创建新的XML布局文件。此文件的名称将替换代码中的simple_list_item_1

在此布局中,创建一个TextView(或任何其他容器)元素并将其命名为text1

然后SimpleCursorAdaptor将与您的联系信息和布局中的text1字段匹配

<?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" >
<TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />