Reputation: 10148
In my Android application,I have a layout, in that have seven days with start and end button, each button open time picker for use choosing his favorite time. My need is have to disable multi finger touch for time picker buttons (start and end time buttons). I mean disable multi finger touch, that is if simultaneously touch two buttons that open two time picker. This is the my layout structure:
<LinearLayout>
.......
<ScrollView>
<LinearLayout>
<TableLayout>
<!--Sunday -->
<TableRow>
<Texview/>
<Button/> <!-- start time -->
<Button/> <!-- endtime -->
</TableRow>
..........
<!--Saturday -->
<TableRow>
<Texview/>
<Button/> <!-- start time -->
<Button/> <!-- endtime -->
</TableRow>
.............
<TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
I have tried android:splitMotionEvents="false"
in every TableRow
,TableLayout
, and ScrollView
and its child LinearLayout
,but its does not disable multi touch for the start and end time buttons. How to disable multi touch for the start and end time buttons? please assist me.
I have tried also the following:
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
Upvotes: 0
Views: 1632
Reputation: 3331
So using CommonsWare answer I got to the right track in my application and here is a quick hack to disable multitouch.
For my app I didn't need multitouches anywhere in my app, infact they were most unwelcome. So in the Activity
by Overriding the dispatchTouchEvent
we get the Action
and if it is MotionEvent.ACTION_POINTER_DOWN
I do not pass it on. Here's the code:
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
return ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN || super.dispatchTouchEvent(ev);
}
But even if you only want to disable one View
's MultiTouch
then you can do so by Overriding either its dispatchTouchEvent()
, onInterceptTouchEvent
or onTouchEvent()
.
A Little Note : Remember to pass on MotionEvent.ACTION_POINTER_UP
uninterrupted or some of your views will remain pressed state.
Upvotes: 2
Reputation: 1006539
There is no means for you to "disable" this, as this has nothing to do with multi-touch. Moreover, they are not simultaneous, but sequential, as both click events route through the main application thread. Hence, you are welcome to use your own business logic to decide to drop the second click event, such as:
Step #1: Have a long lastClickTime=0L
in your activity or fragment that hosts these buttons.
Step #2: Check SystemClock.elapsedRealtime()
at the top of the button's click handler (for this answer, let's assign this to a long now
local variable). If now-lastClickTime
is below some threshold, you ignore the click event, as it was too soon after some other click event. Otherwise, you set lastClickTime
to be now
and do your normal click processing.
Upvotes: 1