How does listSelector of ListView work? - android

Romain Guy himself states that TouchMode does not have any selection or focus in this link. I used android:listSelector="?android:colorPressedHighlight" for a listview and the items I touched retained a blue background. How does this work if TouchMode doesn't have selection?
If listSelector is not the prescribed way to show selected items in touch, how exactly is it done in the youtube app (the red bg in the attached image).

listSelector on ListViews are for phones with bezels/D-pads or GoogleTVs with D-pads
Notice that once you touch them, they remain highlighted. That's because the touch event is mapped to a click event and the selection stays highlighted because that's the only way to keep track of what you've selected (assuming your screen is not touch enabled and for instance you're only controlling the device from the Directional Pad of your remote control).

Related

Android ListView default onHold(?) color

For my list view, each row holds a view (which is a custom view that extends LinearLayout). However, the blue highlighting doesn't appear when you do an onHold action on a list view item. In my experience, this is default, for which you don't even need to code for. How does one turn on or turn off this?
It's not a matter of turning it on or off. It's actually on, but you can't see it.
The "on hold color" effect is achieved via the ListView's selector. It's a state list drawable, means it's displayed differently depending on the view's state (e.g. pressed, selected, enabled, checked, &c).
The only problem is that this selector is drawn behind the item view. Therefore, if the item view is opaque (i.e. it has a non-transparent background) it won't be visible.
The easiest solution is to make your own background a state drawable, and make it transparent when the item is selected, hence the built-in selector will be visible. Another option, if you want, is to set your own selection color, via the same method.
Please check Romain Guy's World of ListView from I/O 2010, around the 31:00 mark (slides here, it's on slide 36).

List item with focusable accessory action using d-pad navigation

On Android, a commonly used pattern in lists is the accessory action. This is often done by putting an extra button on the right of a list item.
For instance, the Alarm clock application lists the different alarm times; on each list item, an extra two-state button allows turning the alarm on or off without entering the alarm properties screen.
Such button is implemented by using a tweaked view that does not show itself pressed when the parent layout is.
One constraint in my project is that such actions should be selectable in non-touch mode i.e. while using d-pad navigation. Actually, only the main part of the list item can be used; it is not possible to focus on the accessory button using the d-pad. This happens on every proposed implementation on blog articles I have read.
A solution is to get rid of focusing the list item itself, but this implies losing much of the ListView or SettingsActivity features depending on the case.
Is it possible to make the extra button focusable in non-touch mode while keeping the normal ListView behaviour? What I want to achieve is, for example, to normally select a list item when using up/down and focus on the accessory button with the left/right keys.

Gallery overlapping items click

I have a Gallery based View with a negative spacing between elements, so that one zoomed out behind the previous, i.e. 'carousel'. Zooming and carousel effect is achieved by Camera transformation.
The problem arises when I try to click right side of foreground item and what I really get is click on item behind it (always to right of it)
Let me enumerate what I've already tried:
setChildrenDrawingOrderEnabled(true);
z coordinate of background item is obviously greater then foreground
one
getChildDrawingOrder was overridden as many ways as possible (and I
found out that it doesn't play any role at all - touch events don't
depend on visibility order of views)
Seems like next(right) child has greater index and therefore a priority of handling UI events, and my z-coordinate/drawing order manipulations don't change anything.
So question: how to make foreground item responsible for all click events on it?

How do you get views to flash red when clicked?

I've noticed that in most stock Android apps when you click on a View of pretty much any sort, the background of the View briefly flashes red before proceeding with whatever it's supposed to do.
I can't figure out how to do this. In some cases it seems to be built in, but not always. The Button objects I have in my Activity all flash red when clicked and I didn't have to do anything to make that happen. However, the items in my ListView do not. Each row in my ListView corresponds to a ViewGroup containing multiple other views. I want the whole row (ViewGroup) to flash red when it's clicked.
I should also point out that, functionally, everything is working properly. I click on my list item and it responds just as I designed it. It just doesn't flash red. Anyone know what I'm missing?
You could just add this to your main layout used for your items in your list :
android:addStatesFromChildren="true" android:background="#android:drawable/list_selector_background"
When one child is selected then all the parent (i.e your layout / the whole row as you said) will get selected, same for other states as pressed, etc. And the selector will apply a short transistion.
Btw, red is vendor dependent, on my Archos, it's a nice orange.
Regards,
Stéphane

ListView items won't show focus when touched

I've got a ListView that works just great, except for this minor annoyance. I can use the trackball/dpad to move up and down my list, and the background changes according to which row has focus. But when I touch the row (click or long click), there's no background change letting me know what's been focused. I've tried setting 'focusable' and 'focusable in touch mode' to true on the rows, but it still doesn't work.
Just in case it matters somehow:
I am setting onClickListeners for
each row.
The row is comprised of
LinearLayouts, TextViews, and a
single ImageView.
Focusable/clickable is 'true' for each row. Have not specified values for these on the ListView.
Trackable does act funny. I can only move between rows after touching inside the ListView. If I scroll trackball above the first item, it's impossible for me to scroll back into the list.
Any thoughts?
I can use the trackball/dpad to move
up and down my list, and the
background changes according to which
row has focus.
No, it doesn't. The background changes according to which row is selected. Selection and focus are not quite the same thing.
But when I touch the row (click or
long click), there's no background
change letting me know what's been
focused.
"In touch mode, there is no focus and no selection."

Categories

Resources