bool LongPress()
{
if (longpressed == 1)
{
int x = (int)downX;
int y = (int)downY;
x -= textview.PaddingLeft;
y -= textview.PaddingTop;
x += textview.ScrollX;
y += textview.ScrollY;
Android.Text.Layout layout = textview.Layout;
int line = layout.GetLineForVertical(y);
int off = layout.GetOffsetForHorizontal(line, x);
var clickspans = ss.GetSpans(off, off, Java.Lang.Class.FromType(typeof(ClickableSpan)));
if (clickspans.Count() > 0)
{
ClickableSpan clickspan = (ClickableSpan)clickspans[0];
startselection = ss.GetSpanStart(clickspan);
endselection = ss.GetSpanEnd(clickspan);
/*
This is where I intend to add Selection.SetSelection(ss, startselection, endselection);
*/
//textview.StartActionMode(textview.CustomSelectionActionModeCallback, ActionModeType.Floating);
}
longpressed = 2;
}
return false;
}
private void TouchLabel(object sender, TouchEventArgs e)
{
MotionEvent motionevt = e.Event;
if (MotionEvent.ActionToString(motionevt.Action) == "ACTION_DOWN")
{
Device.StartTimer(TimeSpan.FromMilliseconds(500), LongPress);
longpressed = 1;
}
else if (MotionEvent.ActionToString(motionevt.Action) == "ACTION_MOVE")
{
longpressed = 2;
}
else if ((MotionEvent.ActionToString(motionevt.Action) == "ACTION_UP") || (MotionEvent.ActionToString(motionevt.Action) == "ACTION_CANCEL"))
{
if (longpressed == 1)
{
longpressed = 2;
}
longpressed = 0;
}
}
Это написано на C # для Xamarin.Android. Я использую таймер для обнаружения «LongPress» и хотел бы установить «выбранный / выделенный» внутри функции LongPress.