Gallery / AdapterView Baby for children

I use the gallery view, where the view corresponding to each element is non-trivial and consists of text as well as several buttons.

When I click to drag the gallery view (somewhere not on one of the buttons), pressing the button with the key pressed and displays as if all the buttons were currently pressed. In addition, the same behavior occurs for the selected state (for example, all the text of the child TextViews changes color).

I am trying to prevent this behavior and found the android: duplicateParentState xml attribute as well as the setDuplicateParentStateEnabled property. It seems like it should do what I'm trying to do, but it seems to have no effect.

Any ideas?

+7
android drawable viewstate gallery android-adapterview
source share
3 answers

Not sure if the duplicateParentState property comes into play, but a break in the source shows that it is never counted for the selected and pressed states. I would like to create a custom view class and override the dispatchSetSelected and dispatchSetPressed methods.

+3
source share

Maybe a little on the late side, but I recently ran into this problem, I have a fix.

dispatchSetSelected and dispatchSetPressed really don't help here, since the methods you really need to override are private in Gallery.

The solution is to add an extra layout (I used a subclass of LinearLayout) around the child view, which overrides setPressed (boolean) and just ignores it. This prevents the gallery from activating its click on children, while allowing these children to activate directly and not stop events from spreading up.

+8
source share

If you manage to spread from the gallery to create your own version, you can simply do:

@Override public boolean onDown(MotionEvent e) { // Ignore onDown events in order to avoid having every child state set to 'pressed' return true; } 

This will still allow the children of the gallery to correctly receive click events, and the swiping / flinging function works as intended.

+1
source share

All Articles