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,
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!
Simplemente agregue la siguiente línea en su vista de texto xml.
android:autoLink="web"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 .
text_view.setOnClickListener(new OnClickListener(){ String url = textView.getText().toString(); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); });