Bug 58827 - Android ListView does not have SetSelector(Drawable drawable).
Summary: Android ListView does not have SetSelector(Drawable drawable).
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.3 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2017-08-16 21:56 UTC by Adam
Modified: 2017-12-01 20:41 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Adam 2017-08-16 21:56:23 UTC
When trying to change the selector for a ListView programmatically to any color I want, I discovered that I am unable to make my own drawable in code.

When looking at the definition for the Android AbsListView in Xamarin, the method SetSelector(Drawable drawable) that is referenced https://developer.android.com/reference/android/widget/AbsListView.html#setSelector(android.graphics.drawable.Drawable) is not available.

I believe it should be.
Comment 1 Jon Douglas [MSFT] 2017-08-16 22:11:52 UTC
Hi Adam,

Thank you for the report. This is one of the cases where we provide the int method and not the Drawable method.

For example, you won't see this method in the following documentation:


The only method you'll find is the following:


There are many ways to workaround this by using the Int32 method, but it would be nicer to have a Drawable one exposed. Thus I am marking this issue as CONFIRMED.


Use the Resources.GetIdentifier method to get the respective identifier of the item, or use the Resource.drawable.resourcename

Now that this bug is CONFIRMED, we will get some Android Engineering eyes on it. Thanks again for the report!
Comment 2 Adam 2017-08-16 22:15:47 UTC
My main problem is that I cannot use a programmatically created drawable, so I have to have something premade in the XML. That is not always the case, especially for Forms projects, where I am looking to use this.
Comment 3 Adam 2017-12-01 19:55:10 UTC
Just looking to touch base on this again.

Any idea when we might get around to this? Just want to know if its pretty low priority or we might see it before the bug gets lost to me.
Comment 4 Jon Douglas [MSFT] 2017-12-01 20:01:15 UTC
Hi Adam,

You should still be able to workaround this with the respective int32 constructor. There are many ways to get the identifier for your XML views as mentioned previously.

This bug does have a workaround and thus a normal priority.
Comment 5 Adam 2017-12-01 20:19:34 UTC
I am a tad confused as to the workaround described.

Are we saying the best workaround to allowing my listview to be any color I want for the selector is to make Resources for them? If I had 15 options I wanted to allow, I would need something in the Resources.xml for each?

I was assuming that the method I referenced would allow me to set any drawable, even a programmatically generated one, which is my goal here.
Comment 6 Jon Douglas [MSFT] 2017-12-01 20:34:04 UTC
Hi Adam,

After looking into this further, I believe this is not actually missing. Rather it is exposed differently via the .Selector property which takes in a Drawable.

You would thus say something like:

            ListView list = new ListView(this);
            list.Selector = Drawable.CreateFromPath("MyPath");


Thus I am marking this bugzilla answered as we tend to use properties over methods to follow C# convention. You can read more on this here:


Please let me know if this solves your problem.
Comment 7 Adam 2017-12-01 20:41:38 UTC
Hmmm.. I was sure I had tried that before and there was no setter. Maybe I am just blind.

Oh well, there is a way to do what I want. That's what matters.  Thanks.