Skip to main content
Active reading. Removed meta information (this belongs in comments).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Don't know if it's worth adding another answer, but just in case...

I had to hunt this down in a couple places, but I finally got this version of the code to work.

strings.xmlFile strings.xml:

<string name="name1">&lt;a href="http://www.google.com">link text1&lt;/a></string> <string name="name2">&lt;a href="http://www.google.com">link text2&lt;/a></string> 

myactivity.xmlFile myactivity.xml:

<TextView  android:id="@+id/textview1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" />   <TextView  android:id="@+id/textview2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" /> 

myactivty.javaFile myactivty.java (in onCreate()):

TextView tv1 = (TextView)findViewById(R.id.textview1); TextView tv2 = (TextView)findViewById(R.id.textview2);   tv1.setText(Html.fromHtml(getResources().getString(R.string.name1))); tv2.setText(Html.fromHtml(getResources().getString(R.string.name2))); tv1.setMovementMethod(LinkMovementMethod.getInstance()); tv2.setMovementMethod(LinkMovementMethod.getInstance()); 

This will create two clickable hyperlinks with the text link text1 and link text2 which redirect the user to googleGoogle.

Don't know if it's worth adding another answer, but just in case...

I had to hunt this down in a couple places but finally got this version of the code to work.

strings.xml:

<string name="name1">&lt;a href="http://www.google.com">link text1&lt;/a></string> <string name="name2">&lt;a href="http://www.google.com">link text2&lt;/a></string> 

myactivity.xml:

<TextView  android:id="@+id/textview1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" />   <TextView  android:id="@+id/textview2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" /> 

myactivty.java (in onCreate()):

TextView tv1 = (TextView)findViewById(R.id.textview1); TextView tv2 = (TextView)findViewById(R.id.textview2);   tv1.setText(Html.fromHtml(getResources().getString(R.string.name1))); tv2.setText(Html.fromHtml(getResources().getString(R.string.name2))); tv1.setMovementMethod(LinkMovementMethod.getInstance()); tv2.setMovementMethod(LinkMovementMethod.getInstance()); 

This will create two clickable hyperlinks with the text link text1 and link text2 which redirect the user to google.

I had to hunt this down in a couple places, but I finally got this version of the code to work.

File strings.xml:

<string name="name1">&lt;a href="http://www.google.com">link text1&lt;/a></string> <string name="name2">&lt;a href="http://www.google.com">link text2&lt;/a></string> 

File myactivity.xml:

<TextView android:id="@+id/textview1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" /> <TextView android:id="@+id/textview2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" /> 

File myactivty.java (in onCreate()):

TextView tv1 = (TextView)findViewById(R.id.textview1); TextView tv2 = (TextView)findViewById(R.id.textview2); tv1.setText(Html.fromHtml(getResources().getString(R.string.name1))); tv2.setText(Html.fromHtml(getResources().getString(R.string.name2))); tv1.setMovementMethod(LinkMovementMethod.getInstance()); tv2.setMovementMethod(LinkMovementMethod.getInstance()); 

This will create two clickable hyperlinks with the text link text1 and link text2 which redirect the user to Google.

Source Link
degausser
  • 177
  • 1
  • 3
  • 9

Don't know if it's worth adding another answer, but just in case...

I had to hunt this down in a couple places but finally got this version of the code to work.

strings.xml:

<string name="name1">&lt;a href="http://www.google.com">link text1&lt;/a></string> <string name="name2">&lt;a href="http://www.google.com">link text2&lt;/a></string> 

myactivity.xml:

<TextView android:id="@+id/textview1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" /> <TextView android:id="@+id/textview2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="5dp" /> 

myactivty.java (in onCreate()):

TextView tv1 = (TextView)findViewById(R.id.textview1); TextView tv2 = (TextView)findViewById(R.id.textview2); tv1.setText(Html.fromHtml(getResources().getString(R.string.name1))); tv2.setText(Html.fromHtml(getResources().getString(R.string.name2))); tv1.setMovementMethod(LinkMovementMethod.getInstance()); tv2.setMovementMethod(LinkMovementMethod.getInstance()); 

This will create two clickable hyperlinks with the text link text1 and link text2 which redirect the user to google.