简体   繁体   English

setMovementMethod 在 android textview 中不起作用

[英]setMovementMethod doesn't work in android textview

I have a textview whose text is coming from database.我有一个 textview,其文本来自数据库。 This text can be normal text or it can be a link or both.此文本可以是普通文本,也可以是链接,或两者兼而有之。 For this, I am parsing text in html using Html.fromHtml(myText) .为此,我正在使用Html.fromHtml(myText)解析 html 中的文本。 So that link can be detected and display as clickable.这样就可以检测到该链接并将其显示为可点击。 This is working fine.这工作正常。 It displays clickable string for links and non-clickable for normal text.它为链接显示可点击的字符串,为普通文本显示不可点击的字符串。 But when I click that text, it doesn't work and nothing happens.但是当我单击该文本时,它不起作用并且没有任何反应。 This is what I am getting from server as text:这是我从服务器获得的文本:

Dear user:

Your review titled <a href="http://example.com/review/someText-1069459" target="blank">Normal verified negative 1 desktop</a> on the product <a href="http://example.com/product-reviews/text-925766045"  target="blank">Clickable Text</a> has been resolved.

To check corporate response  <a target="blank" href="http://example.com/interact.php?add=http://example.com/blog/ejhhspsqmn/Please-talk-about-your-companys-products-and-services-onlyPlease-present-your-post-in-an-objectiv&session_id=Se9qExA6JSY%3d">Click here</a>

Have a great day! 

Regards,
Head - Member Support

To make clickable text, I use setMovementMethod like below:为了制作可点击的文本,我使用如下的 setMovementMethod:

textView.setText(Html.fromHtml(myText));
textView.setMovementMethod(LinkMovementMethod.getInstance());

But its not working.但它不起作用。 Is there anything that I am missing to add in code?有什么我想在代码中添加的吗? Also I am using android:autoLink="web" in xml.我也在 xml 中使用android:autoLink="web"

在此处输入图像描述

删除xml中的android:autoLink =“ web”。

You can either user LinkMoveMethod interface or Linkify 您可以使用LinkMoveMethod接口或Linkify

Example :---- 例子:----

TextViewObject.setText(Html.fromHtml("YOur Text "));
TextViewObj.setMovementMethod(LinkMovementMethod.getInstance());

OR 要么

Linkify.addLinks(new SpannableString(Html.fromHtml("Your Text"));

Adding these attributes to textview in xml worked for me将这些属性添加到 xml 中的 textview 对我有用

android:focusable="true" android:scrollbars="vertical" android:focusable="true" android:scrollbars="vertical"

then in Kotlin然后在 Kotlin

textview.movementMethod = ScrollingMovementMethod()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM