1

I'm trying to set a ListView selector like this:

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

And I get:

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

Any idea on why this is happening?

m0skit0
  • 25,268
  • 11
  • 79
  • 127
  • Based on [this](http://stackoverflow.com/questions/2204994/how-do-you-activate-checkmarks-in-list-activity), it looks like simple_list_item_checked is supposed to be passed to the list adapter when it's created, not set directly on the ListView, and based on [this](http://stackoverflow.com/questions/11762235/android-listview-setselector-issue), it looks like ListView.setSelector is expecting a drawable, not a layout. Can you try setting simple_list_item_checked on your adapter, or is there some reason that won't work in your case? – Andy Oct 02 '12 at 17:48

1 Answers1

3

You're are trying to set as a selector a layout resource from the SDK(that layout file in particular is a simple CheckedTextView element) which obviously will not work as it expects a drawable resource. You most likely want a drawable:

android.R.drawable.something

(for example: android.R.drawable.list_selector_background , the default selector)

user
  • 86,916
  • 18
  • 197
  • 190
  • @m0skit0 The `android.R.drawable.list_selector` doesn't work? You may want to try the `drawSelectorOnTop` attribute on the `ListView` and see if that works. – user Oct 03 '12 at 07:54
  • Nope, no go. But if I use `android.R.drawable.screen_background_light_transparent` it does work... but the selector only appears if I scroll the `ListView`. Btw the `ListView` is on a `PopupWindow`. – m0skit0 Oct 03 '12 at 08:11
  • @m0skit0 The selector from my answer should have worked as it's the default one, I think it has something to do with the `PopupWindow` which has a special focus status(which is used in that selector drawable). I don't know how you created the `PopupWindow` but try to use the last constructor the one which allows the popup to be focusable. – user Oct 03 '12 at 08:28
  • Yes, I'm pretty sure it has to do with `PopupWindow`. I already set the `PopupWindow` to be focusable by doing `window.setFocusable(true);` – m0skit0 Oct 03 '12 at 08:31
  • 1
    Ok got it to work: in fact I had to remove the focusable state. Thank you for your help! – m0skit0 Oct 03 '12 at 08:38