【Android】onLongClick for TextView fires link inside textview(摘自stackoverflow)

In my app I have textViews with links inside. I need to separate normal click which will open web link and longClick which will open context menu. But whenever I make longClick, when I release my finger it fires web link, which opens browser.

TextView textView = new TextView(context);
textView.setAutoLinkMask(Linkify.WEB_URLS);
textView.setText(some text with web links);
textView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
Log.d("RAFL", "longclick works");
return true;
}
});

textview.setOnLongClickListener(new View.OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
        isLongClick= true;
        return true;
    }
});
textview.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP && isLongClick){
            isLongClick= false;
            return true;
        }
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            isLongClick= false;
        }
        return v.onTouchEvent(event);
    }

});

你可能感兴趣的:(【Android】onLongClick for TextView fires link inside textview(摘自stackoverflow))