Android ClickableSpan 没有调用 onClick [英] Android ClickableSpan not calling onClick
本文介绍了Android ClickableSpan 没有调用 onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个 ClickableSpan,它可以正常显示适当的文字加下划线.但是,点击未注册.你知道我做错了吗???
I am creating a ClickableSpan, and it is displaying properly with the proper text underlined. However, the clicks are not registering. Do you know what I am doing wrong???
谢谢,维克多
这里是代码片段:
view.setText("This is a test");
ClickableSpan span = new ClickableSpan() {
@Override
public void onClick(View widget) {
log("Clicked");
}
};
view.getText().setSpan(span, 0, view.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
推荐答案
你试过在包含span的TextView上设置MovementMethod吗?您需要这样做才能使点击工作...
Have you tried setting the MovementMethod on the TextView that contains the span? You need to do that to make the clicking work...
tv.setMovementMethod(LinkMovementMethod.getInstance());
这篇关于Android ClickableSpan 没有调用 onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文