I would like to link some text on a TextView
to an Activity
. This is the TextView that I have:
<TextView
android:id="@+id/termsLink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/terms"
android:layout_weight="4"/>
where @string/terms
is:
<string name="terms">Accept <a href="#">terms & conditions.</a>.</string>
If I had a link to a webpage I would do it like this:
TextView link = (TextView) findViewById(R.id.termsLink);
link.setMovementMethod(LinkMovementMethod.getInstance());
but I do not know how to start an Activity when I press the link as when it is a real link (that it links a webpage).
EDIT: Please note that I do not have to handle the onClick
event in the full text because the link is only on the part "terms & conditions"
.
EDIT 2: I have tried using two TextView
as suggested on the comments and one of the answers below to make the same effect. But sometimes (depending on the screen) the "terms & conditions"
part occupy two lines because it does not fill properly on the available space so the second line it is shown on the second TextView
and not on the begining of the second line.
The effect is similar to this:
Accept terms &
conditions.
and I would like that it would be like this:
Accept terms &
conditions.
Thanks in advance!