2 - I haven't had to override StateListDrawable when adding a new state for
my drawables. I only had to override getDrawableState in the view (subclass)
to make sure that my new state gets propageted into the drawable's state
array.

3 - No, I don't. I just know there is a separate drawable for the selector.

Looking at the source, AbsListView has a onCreateDrawableState() method that
you can override (it's a framework method that is meant to be overriden, so
it's protected).

http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/AbsListView.java

And it looks like AbsListView just copies its own state into the selector
state (same file, drawableStateChanged).

So the issue is how to push your state, which is per-item, into the list
view selector. I would do this with a custom interface in the adapter, there
are probably other ways too.

4 - I haven't actually done the exact thing you're trying to do, so don't
have code I could post. I am sharing some ideas, hoping that they might be
useful to you.

5 - Gmail for Android uses the background color to indicate read / unread
state for messages (in the message list view). This background is overriden
by the selector, just like you are saying, but frankly, I never noticed
until now, when I went to check what it looks like there.

Here is another idea - if you are building a non-standard,
graphics-intensive UI, perhaps you could use a selector drawable that shows
pressed/selected states in a non-standard way, too. I did this for my
current project, and quite liked the look (YMMV):

http://kmansoft.wordpress.com/2011/01/11/checkable-image-button/

-- Kostya

2011/1/16 poohtbear <eyaltg...@gmail.com>

> Hi Kostya.
> 1. i know how to add a new attribute to the selector, i can do it
> programatically using the original list's selector and save me some
> work.
> 2. in StateListDrawable you have a protected method that acts on those
> states, and it's stated specifically that you need to override it to
> act on your own states, so just adding a state will not do, i need my
> own StateListDrawable.
> 3. how and where in ListView the selector states are determined ?
> KeyDown\KeyUp events ? pointerPressed events ? is there a  main
> function where it all goes to to set the current selector state on a
> specific list item that i can override ? i'm not sure this method wont
> be private making me override lots of other methods...
> 4. it would have been easier if you could just post a simple selector
> xml and a short ListView example that uses the new state, what you
> wrote here is pretty much just stating the obvious in high level
> without giving the specific details i wondered about...
>
> 5. i think i explained that i can't just 'set the background' because
> than the selected and clicked drawables will be hidden by that
> background. i didn't check though what will happen if the background
> will be StateListDrawable itself.
>
> On Jan 13, 5:21 pm, Kostya Vasilyev <kmans...@gmail.com> wrote:
> > You can probably do this by:
> >
> > - Creating your own styleable to declare the new attribute;
> > - Creating your own state-list drawable to use the new atribute;
> > - Setting it as the "listSelector" for the list view;
> > - Subclassing ListView to propagate the new attribute value into the
> > selector.
> >
> > On the other hand, it's probably going to be easier to just set the
> > background color in your adapter's getView.
> >
> > -- Kostya
> >
> > 13.01.2011 18:01,poohtbearпишет:
> >
> >
> >
> > > I have a list view with relativeLayout with all sorts of widgets
> > > (TextViews, RatingBars, ImageViews etc...).
> > > I use my own adapter to populate the ListView.
> >
> > > The items in the adapter, besides being selected \ pressed \not
> > > focused have an extra state: 'viewed'.
> > > Baiscally i want that items that have state viewed set to true will be
> > > drawn with blue background and items with viewed set to false with
> > > white\transparent background.
> >
> > > The problem is that i can't set the background on the View itself
> > > since it will hide the selector, i'm not sure regarding adding extra
> > > state since i know how to add it using addState on the current
> > > selector, but i have no clue how to cause the list to use the extra
> > > state, or how to use different selector for different item types.
> >
> > > Any help ?
> >
> > --
> > Kostya Vasilyev -- WiFi Manager + pretty widget --
> http://kmansoft.wordpress.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to