Android Linkify text - Spannable Text in Single Text View - As like Twitter tweet

I have a textView and text like

"This is the Simple Text with KeyWord and the Link to browse"

in the above text i want to make..

clicking on the Link goes to open that URL AND clicking on that KeyWord open a new Activity in my application

also, There is an click event for the Whole TextView even.

Please help me finding a solution. Thank You, MKJParekh


What you can do is create a Custom ClickableSpan as below,

class MyCustomSpannable extends ClickableSpan
    String Url;
    public MyCustomSpannable(String Url) {
        this.Url = Url;
    public void updateDrawState(TextPaint ds) {
            // Customize your Text Look if required
        ds.setShadowLayer(10, 1, 1, Color.WHITE);
    public void onClick(View widget) {
    public String getUrl() {
        return Url;

And the use its onClick() for opening an Activity or URL. I am adding a demo for loading a URL in WebView.

String text = "";
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
MyCustomSpannable customSpannable = new MyCustomSpannable(

            public void onClick(View widget) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
        stringBuilder.setSpan(customSpannable, 0, text.length(),

        textView.setText( stringBuilder, BufferType.SPANNABLE );

Generate your TextView in the following manner:

TextView t3 = (TextView) findViewById(;
t3.setText(Html.fromHtml("This is the Simple Text with 
    <a href=\'\'>Keyword</a> and the 
    <a href='startActivityFromLink://some_info'>Link</a> to browse"));

Specify your activity the following way:

<activity android:name=".TestActivity"
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <data android:scheme="startActivityFromLink" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />

I think it should work. Might require some tweaking. I did not get the time to test it. Let me know if it works.

I have used the same thing which I answered here in This Question

For that I have used this LinkEnabledTextView and that become easy for me to do the task.

Make Keyword and The link into different TextViews.

Then set the TextView.onClickListener() after you do this.

This is the easiest way, and more logic way.

Need Your Help

Dealing with Options in Scala Play Template

scala playframework playframework-2.0 playframework-2.1

I am trying reference things of type option in my Scala Play template. I've been trying to use this resource:

How to download iPad Mini simulator

ios xcode ipad ios-simulator

I want to test my application on iPad mini screen in Xcode 8.2, but I could not find the simulator for the same.