Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
How do I open a browser on clicking a text link in TextView

I made an activity that has some text. I made a link clickable in TextView but and it is working fine (link is visible with underline).

But when I click the link it says Unfortunately app has stopped responding Here is my code.

The TextView code:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/home"
    android:text="@string/google" />

The Java code (in protected void onCreate(Bundle savedInstanceState) ):

 TextView txt= (TextView) findViewById(R.id.home); //txt is object of TextView
    txt.setMovementMethod(LinkMovementMethod.getInstance());

The string.xml code:

<string name="google">
    <a href="www.google.com">Home page</a>
</string>

This is what my app shows,

App screenshot

Now if I click Home Page link the error message saying Unfortunately app has stopped not responding appears What should I do?

Please help!

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Just add following line in your textview xml.

android:autoLink="web"
about 4 years ago · Santiago Trujillo Report

0

Thanks to those who helped me by their answers

This is what the complete answer looks like.

In the TextView of activityname.xml write android:autoLink="web"

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/home"
    android:autoLink="web
    android:text="@string/google" />

In the java file write create onClickListener()

TextView txt= (TextView) findViewById(R.id.home); //txt is object of TextView
    txt.setMovementMethod(LinkMovementMethod.getInstance());
    txt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW);
            browserIntent.setData(Uri.parse("http://www.google.com"));
            startActivity(browserIntent);
        }
    });

No changes in the string.xml file

Thanks to @AdnanAmjad @sarvesh @Mikejess and to the guy who deleted his comment

about 4 years ago · Santiago Trujillo Report

0

text_view.setOnClickListener(new OnClickListener(){

     String url = textView.getText().toString();
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);

});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!