Add Clickable links to TextView in Sketchware

Here are two ways of adding clickable links to TextView in Sketchware.


Method 1

1. In main.xml add a TextView text_html.

2. Create a String html_string.

3. In onCreate event:
a. Set the text of html_string to your text in html form with links declared in <a> tag ( <a href="http://google.com"> Google </a> will display 'Google' in link form).

So let's set String html_string to:
<b>text_html_program: Explicit links using &lt;a&gt; markup.</b> This has markup for a <a href="http://www.google.com">link</a> specified via an &lt;a&gt; tag. Use a "tel:" URL to <a href="tel:4155551212">dial a phone number</a>.

b. Display this String in TextView. In an add source directly block put following codes:
text_html.setText( Html.fromHtml(html_string));
text_html.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());

Method 2

1. In main.xml add a TextView text_spannable.

2. Create a String mystring.

3. In onCreate event:
a. Set the text of mystring to your text.
So let's set String mystring to:
text_spannable: Manually created spans. Click here to dial the phone and here to visit Yahoo.

b. Use an add source directly block put following codes:
// Convert this String to a Spannable String ss.
SpannableString ss = new SpannableString(mystring);

// Make Substring 0-39 bold

ss.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, 39, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

// linkify substring 46-50 (first 'here') and substring 73-77 (second 'here') of ss.
ss.setSpan(new android.text.style.URLSpan("tel:4155551212"), 46, 50, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

ss.setSpan(new android.text.style.URLSpan("http://yahoo.com"), 73, 77, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

// Display Spannable String in TextView.
text_spannable.setText(ss);
text_spannable.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());


Watch Video below: