安卓的TextView的链接给NullPointerException异常onLongClick [英] Android : TextView with links Give NullPointerException onLongClick

查看:146
本文介绍了安卓的TextView的链接给NullPointerException异常onLongClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使通过链接可以:

I can enable links via either:

A)在code

Linkify.addLinks(textView, Linkify.ALL); 

B)的XML

B) in XML

android:autoLink="all"    
android:linksClickable="true"

每当我能够链接,长时间点击侦听获取的视图,这是一个视图 - 持有人的标签。由此看来持有者对象返回空每当文本视图有任何联系在里面。

Whenever I enable links, a long click-listener fetches the tag of the View, which is a View-Holder. This View-holder object is returned as null whenever the Text-view has any links in it.

我一直在使用XML和code办法尝试,但它仍然是返回一个空查看-Holder对象!

I have tried using both XML and Code approaches but it still is returning a null View-Holder object!

推荐答案

使用此给链接一个TextView,然后实现longclick监听器

Use this to give link to a textview and then implement longclick listener

TextView.setText(Html.fromHtml("<a href=\"your link here">Click here</a> "));
TextView.setMovementMethod(LinkMovementMethod.getInstance());

这篇关于安卓的TextView的链接给NullPointerException异常onLongClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆