I want to open link which is in text view in the form of text:type="autolink"and it contains some URL but when a user tap on it, opens browser instead of webview activity

For Example

{<TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:autoLink="web"android:text="www.facebook.com"android:id="@+id/iimage" />}

so please tell if a user clicks on this link it opens in webView in WebView activity. How to do this

share|improve this question

    You can do this simply by:

     iimage.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent=new Intent(currentactivity, youractivity.class);intent.putExtra("url", your_url );startActivity(intent);finish();}});

    Inside onCreate of your youractivity

    String urltoload=getIntent().getStringExtra("url");webView.loadUrl(url);

    Hope this helps.

    share|improve this answer
    • Except www.google.com no other links is not working like facebook,youtube– user9119525yesterday
    • I added some more code of lines and starts working– user9119525yesterday
    • Were you passing the whole URL like " facebook.com/";?– nimi011218 hours ago

    You will need to set a Spannable to your textview and set the click listener on that Spannable.

    Here you have an example i took from some answer: Android: ClickableSpan in clickable TextView

    TextView tv=(TextView)findViewById(R.id.textview01); Spannable span=Spannable.Factory.getInstance().newSpannable("test link span"); span.setSpan(new ClickableSpan() { @Overridepublic void onClick(View v) { Log.d("main", "link clicked");Toast.makeText(Main.this, "link clicked", Toast.LENGTH_SHORT).show(); } }, 5, 9, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);// All the rest will have the same spannable.ClickableSpan cs=new ClickableSpan() { @Overridepublic void onClick(View v) { Log.d("main", "textview clicked");Toast.makeText(Main.this, "textview clicked", Toast.LENGTH_SHORT).show(); } };// set the "test " spannable.span.setSpan(cs, 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);// set the " span" spannablespan.setSpan(cs, 6, span.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);tv.setText(span);tv.setMovementMethod(LinkMovementMethod.getInstance());
    share|improve this answer

      Look How can we open TextView's links into Webview

      But actually all you need is webView.loadUrl("www.facebook.com")

      share|improve this answer
      • no bro I am trying to open text view links in other activity with webview not just by loading loadUrl();– user9119525Feb 14 at 21:07
      • Well, ok. And what a problem to pass String to other activity in intent extras, in activity extract it and put to webView?– 600Feb 14 at 21:10

      Your Answer


      By posting your answer, you agree to the privacy policy and terms of service.

      Not the answer you're looking for? Browse other questions tagged or ask your own question.