如何解决ClickableSpan的点击事件和长按事件3事件冲突问题

如何解决ClickableSpan的点击事件和长按事件3事件冲突问题

2个回答

解决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;
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐