如何解决ClickableSpan的点击事件和长按事件3事件冲突问题
解决ClickableSpan的点击事件和长按事件3事件冲突问题
如何解决ClickableSpan的点击事件和长按事件3
public class ControlClickSpanTextView extends AppCompatTextView {
private static final String TAG = "AutoLinkTextView";
private long mTime;
private boolean mLinkIsResponseLongClick = false;
public ControlClickSpanTextView(Context context) {
super(context);
}
public ControlClickSpanTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ControlClickSpanTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public boolean isLinkIsResponseLongClick(www.thd178.com/) {
return mLinkIsResponseLongClick;
}
public void setLinkIsResponseLongClick(boolean linkIsResponseLongClick) {
this.mLinkIsResponseLongClick =www.xgll521.com linkIsResponseLongClick;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
CharSequence text = getText();
if (text == null) {
return super.onTouchEvent(event);
}
if (!mLinkIsResponseLongClick && text instanceof Spannable) {
int end = text.length();
Spannable spannable = (Spannable) text;
ClickableSpan[] clickableSpans = spannable.getSpans(0, end, ClickableSpan.class);
if (clickableSpans == null |www.dasheng178.com| clickableSpans.length == 0) {
return super.onTouchEvent(event);
}
if (event.getAction(www.ysyl157.com) == MotionEvent.ACTION_DOWN) {
mTime = System.currentTimeMillis();
} else if (event.getAction(yongshiyule178.com) == MotionEvent.ACTION_UP) {
if (System.currentTimeMillis() - mTime > 500) {
return true;