On Sat, Nov 1, 2008 at 8:59 PM, Eric <[EMAIL PROTECTED]> wrote:

>
> Interesting.  I'm returning false, because when I was using the Button
> class the button highlighting didn't work right if my touchHandler
> returned true.  See Romain Guy's reply to my question in this thread:
>
> http://groups.google.com/group/android-developers/browse_thread/thread/0133ac99a57f7f91#
> I haven't previously tried returning true from a touchHandler for the
> ImageView or ImageButton classes.
>
> Results:
>
> With the ImageView class, I get ACTION_UP only if my touchHandler
> returns true.
>
> With the ImageButton class, I get ACTION_UP regardless of whether my
> touchHandler returns true or false, but if I return false, the button
> highlighting doesn't work correctly.


Ah, this is since View.dispatchTouchEvent won't call View.onTouchEvent
(where the highlighting is done) if the OnTouchListener returns true.


>
>
> With my own subclass of ImageButton, which forces the defStyle to 0
> (rather than the value com.android.internal.R.attr.imageButtonStyle
> used in the ImageButton class), I get ACTION_UP only if my
> touchHandler returns true.
>
> Why does the defStyle affect this?
>

defStyle defines default values for some of the XML attributes.  For
example, for an ImageButton:

        <item name="android:focusable">true</item>
        <item name="android:clickable">true</item>
        <item name="android:scaleType">center</item>
        <item name="android:background">@android:drawable/btn_default</item>

So, the clickable=true from the default style makes View.onTouchEvent return
true on ACTION_DOWN.

For the quickest solution, you can just use an ImageButton and set the
background to null (or @null if doing this from XML).


> Where in the view or widget sources is the decision as to whether to
> deliver ACTION_UP events being made?


ViewGroup.dispatchTouchEvent.  It tracks a motion target that received the
down (successful receipt is when the receiver returns true), and later
delivers move and up events to that motion target.  In our case, we returned
false so the ImageView/Button doesn't get set as the motion target.

jason



>
>
> Thanks,
> Eric
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to