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

254
Views
¿Cómo abro un navegador al hacer clic en un enlace de texto en TextView?

Hice una actividad que tiene algo de texto. Hice un enlace en el que se puede hacer clic en TextView pero funciona bien (el enlace se ve subrayado).

Pero cuando hago clic en el enlace, dice Unfortunately app has stopped responding Aquí está mi código.

El código TextView :

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

El código Java (en protected void onCreate(Bundle savedInstanceState) ):

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

El código string.xml :

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

Esto es lo que muestra mi aplicación,

Captura de pantalla de la aplicación

Ahora, si hago clic en el enlace de la página de inicio, Unfortunately app has stopped not responding appears ¿Qué debo hacer?

¡Por favor ayuda!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Simplemente agregue la siguiente línea en su vista de texto xml.

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

0

Gracias a los que me ayudaron con sus respuestas

Así es como se ve la respuesta completa.

En TextView de activityname.xml escribe 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" />

En el archivo java , escriba 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); } });

Sin cambios en el archivo string.xml

Gracias a @AdnanAmjad @sarvesh @Mikejess y al tipo que eliminó su comentario .

over 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); });
over 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!