Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically creating links in TextViews
    primarykey
    data
    text
    <p>I need to be able to create a link for a TextView in an app, but the actual URL to which the link will point needs to be added dynamically.</p> <p>Through research here on SO, I found the following code:</p> <pre><code> textView.setText(Html.fromHtml( "&lt;b&gt;text3:&lt;/b&gt; Text with a " + "&lt;a href=\"http://www.google.com\"&gt;link&lt;/a&gt; " + "created in the Java source code using HTML.")); textView.setMovementMethod(LinkMovementMethod.getInstance()); </code></pre> <p>This allegedly will set a link in the TextView as it would in HTML. This is exactly what I need to do, but I need the URL to be dynamic, based on a string variable that would be passed to the <code>setText()</code>. How do I easily go about doing this? </p> <p>To clarify: I want to display the word "website" is a link, and I need the URL to which that link directs to be dynamically updated based on the specific path that brought the user to that view.</p> <p>Thanks!</p> <p>EDIT: Here is the updated code:</p> <pre><code>String linkedText = "&lt;b&gt;text3:&lt;/b&gt; Text with a " + String.format("&lt;a href=\"%s\"&gt;link&lt;/a&gt; ", WEB) + "created in the Java source code using HTML."; web.setText(Html.fromHtml(linkedText)); web.setMovementMethod(LinkMovementMethod.getInstance()); </code></pre> <p>Here is the TextView's XML:</p> <pre><code> &lt;TextView android:id="@+id/vWeb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/vPhone" android:layout_marginTop="5dp" android:layout_toRightOf="@+id/webIcon" android:paddingLeft="1dp" android:autoLink="web" android:textIsSelectable="true" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload