0

My requirement is to handle a double tap in my Grid control for Xamarin.Android without using gestures. I already have a selection operation to be performed on a single click.

I have implemented the double tap logic in the OnSingleClick event of the IOnSingleClick interface. This is how it works: A single click will select the row of the grid and another single click will deselect the row of the grid.

So now when I want to double tap, I don't want the selection to happen. How can i achieve this ? I cant use the OnSingleTapConfirmed() since the selection operation is handled in the key up event and hence a delay will happen which affects the user experience.

public void OnClick(View v)
{           
    long currentTouchTime = Java.Lang.JavaSystem.CurrentTimeMillis();

    if (previousClickTime == 0 || (currentTouchTime - previousClickTime > 500))
    {
        previousClickTime = currentTouchTime;
        //count = 0;

        if (this.DataColumn != null && previousClickTime != 0)
        {
            Handler.PostDelayed(action, 500);
        }                
        count = 1;
    }
    else
    {
        Toast.MakeText(this.Context, "Double Tapped", ToastLength.Short).Show();                                        
    }
}
Dan Mašek
  • 17,852
  • 6
  • 57
  • 85

2 Answers2

0

Unfortunately, there is no out of the box APIs in Android to support double-tap events.

You have to use the `GestureDetector, you can find the Java implementation here to port it to C#

Community
  • 1
  • 1
Prashant Cholachagudda
  • 13,012
  • 23
  • 97
  • 162
0

I have implemented the double tap logic with time delay calculations in the OnSingleClick event. I calculate the time diff between two successive clicks and decide the operation based on boolean flags. I have set 250 milli seconds as the wait for double tap. this way my selection operation to be performed on a single click does not take away the user experience eventhough it is delayed by 250 ms.

public void OnClick(Android.Views.View v)
    {
        long currentTouchTime = Java.Lang.JavaSystem.CurrentTimeMillis();
        if (previousClickTime == 0 || (currentTouchTime - previousClickTime > 250))
        {
            isDoubleTapped = false;
            previousClickTime = currentTouchTime;
            if (this.Element.DataColumn != null && previousClickTime != 0)
                Handler.PostDelayed(action, 250);
        }
        else
        {
            isDoubleTapped = true;
            Toast.MakeText(this.Context, "Double Tapped", ToastLength.Short).Show();
        }
    }

private void action() { if (!isDoubleTapped) //perform selection }