1

I have a ViewPager that holds views which are added dynamically (inflated from XML) and controlled by a PagerAdapter. The views which are added have some simple EditTexts and a SurfaceView which holds a touchable chart.

In order to drop focus from the EditTexts when the user is paging through the views, I followed this suggestion and added the following to the dynamically added view layout:

android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"

That worked perfectly, but it introduced a new problem. The user also needs to be able to touch the chart on the SurfaceView, but the SurfaceView is registering each touch as 2 touches (if I remove the above XML attributes, it works correctly but then I have the EditText focus issue).

I tried different variations of the above XML attributes (making some true and some false), but that didn't produce the desired result. I also tried adding an OnFocusChangeListener to the EditTexts so that the above attributes would be true if any had focus and false otherwise.

I've done some searching but couldn't find what I was looking for - any help would be greatly appreciated.

Community
  • 1
  • 1
user1205577
  • 2,388
  • 9
  • 35
  • 47

1 Answers1

2

Are you using onTouchEvent? If so, it registers for:

ACTION_UP
ACTION_DOWN
ACTION_MOVE
and more

You can tell what is happening and handle only ACTION_UP events like this:

public boolean onTouchEvent(MotionEvent event)
{
    int action = event.getAction();

    //When the user lifts up...
    if (action==MotionEvent.ACTION_UP) 
    {
        //Do something here
    }
}

This may be why you pick up two touches.

Shellum
  • 3,159
  • 2
  • 21
  • 26