为ListView设置选择器时出现异常

时间:2012-10-02 17:35:09

标签: android android-listview

我正在尝试像这样设置ListView选择器:

fileList.setSelector(android.R.layout.simple_list_item_checked);

我得到了:

10-02 18:30:08.365: E/AndroidRuntime(13294): java.lang.IllegalStateException: Could not execute method of the activity
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.view.View$1.onClick(View.java:3044)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.view.View.performClick(View.java:3511)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.view.View$PerformClick.run(View.java:14109)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.os.Handler.handleCallback(Handler.java:605)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.os.Looper.loop(Looper.java:137)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.app.ActivityThread.main(ActivityThread.java:4424)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at java.lang.reflect.Method.invokeNative(Native Method)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at java.lang.reflect.Method.invoke(Method.java:511)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at dalvik.system.NativeStart.main(Native Method)
10-02 18:30:08.365: E/AndroidRuntime(13294): Caused by: java.lang.reflect.InvocationTargetException
10-02 18:30:08.365: E/AndroidRuntime(13294):    at java.lang.reflect.Method.invokeNative(Native Method)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at java.lang.reflect.Method.invoke(Method.java:511)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.view.View$1.onClick(View.java:3039)
10-02 18:30:08.365: E/AndroidRuntime(13294):    ... 11 more
10-02 18:30:08.365: E/AndroidRuntime(13294): Caused by: android.content.res.Resources$NotFoundException: File res/layout/simple_list_item_checked.xml from drawable resource ID #0x1090005
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.content.res.Resources.loadDrawable(Resources.java:1923)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.content.res.Resources.getDrawable(Resources.java:664)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.widget.AbsListView.setSelector(AbsListView.java:2196)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at com.blablabla.android.helpers.gui.dialog.fexplorer.FileExplorer.initializeViews(FileExplorer.java:85)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at com.blablabla.android.helpers.gui.dialog.fexplorer.FileExplorer.<init>(FileExplorer.java:76)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at com.example.pruebaandroid.MainActivity.click(MainActivity.java:34)
10-02 18:30:08.365: E/AndroidRuntime(13294):    ... 14 more
10-02 18:30:08.365: E/AndroidRuntime(13294): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag CheckedTextView
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:863)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
10-02 18:30:08.365: E/AndroidRuntime(13294):    at android.content.res.Resources.loadDrawable(Resources.java:1920)
10-02 18:30:08.365: E/AndroidRuntime(13294):    ... 19 more

有关为何发生这种情况的任何想法?

1 个答案:

答案 0 :(得分:3)

您正在尝试将{{1>}中的布局资源设置为选择器(该布局文件特别是一个简单的SDK元素),这显然不会因为它需要一个 drawable 资源。您最有可能想要 drawable

CheckedTextView

(例如:android.R.drawable.something ,默认选择器)