Android: How to make Linkify links not long

I have some TextViews that I use Linkify on. I'd like for the links to not be long-clickable. Using setLongClickable(false) on the TextViews doesn't have any affect on the Linkify links. Is there any way to make these links not long-clickable?


这会对你有所帮助

Spannable span = Spannable.Factory.getInstance().newSpannable("my span text"); 
             Linkify.addLinks(span, Linkify.ALL);
         URLSpan[] uspans = span.getSpans(0, mTextAdData.length(), URLSpan.class);

    int i = 0;
            for (URLSpan uspan : uspans) {
                int start = span.getSpanStart(uspan);
                int end = span.getSpanEnd(uspan);
                span.removeSpan(uspan);
                MyUrlSpan uspan1 = new MyUrlSpan(uspan.getURL());
                span.setSpan(uspan1, start, end, 0);
                if (i != start) {
                    // From i to start of this span set a custom span
                    span.setSpan(new MyUrlSpan(), i, start,
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                i = end;
            }

    public class MyUrlSpan extends URLSpan implements OnLongClickListener {
                public MyUrlSpan(String string) {
                    super(string);
                }

                       @Override
                       public void onClick(View v){
                       }

                       @Override
                public boolean onLongClick(View v) {
                    return false;
                }
        }

原来,解决办法很简单:

textview.setOnLongClickListener(new OnLongClickListener(){
    public boolean onLongClick(View v) {
        return true;
    }
});

尝试这个...

    Link.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            Link.setLongClickable(false);
            return false;
        }
    });

    Link.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!Link.isLongClickable()) {
                Link.setLongClickable(true);
                return;
            }

            //  Link your page 
        }
    });
链接地址: http://www.djcxy.com/p/12954.html

上一篇: 你可以在不同的OSGi包中使用JSF自定义组件吗?

下一篇: Android:如何使Linkify链接不长