Android ClickableSpan que no llama onClick

Estoy creando un ClickableSpan, y está exhibiendo correctamente con el texto correcto subrayado. Sin embargo, los clics no se están registrando. ¿Sabes lo que estoy haciendo mal ??? Gracias, Victor Aquí está el fragmento de código:

view.setText("This is a test"); ClickableSpan span = new ClickableSpan() { @Override public void onClick(View widget) { log("Clicked"); } }; view.getText().setSpan(span, 0, view.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 

¿Ha intentado establecer el método MovementMethod en el TextView que contiene el span? Tienes que hacer eso para hacer clic en el trabajo …

 tv.setMovementMethod(LinkMovementMethod.getInstance()); 

Después de algún ensayo y error, la secuencia de establecer el tv.setMovementMethod(LinkMovementMethod.getInstance()); sí importa.

Aquí está mi código completo

 String stringTerms = getString(R.string.sign_up_terms); Spannable spannable = new SpannableString(stringTerms); int indexTermsStart = stringTerms.indexOf("Terms"); int indexTermsEnd = indexTermsStart + 18; spannable.setSpan(new UnderlineSpan(), indexTermsStart, indexTermsEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(getColor(R.color.theme)), indexTermsStart, indexTermsEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ClickableSpan() { @Override public void onClick(View widget) { Log.d(TAG, "TODO onClick.. Terms and Condition"); } }, indexTermsStart, indexTermsEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); int indexPolicyStart = stringTerms.indexOf("Privacy"); int indexPolicyEnd = indexPolicyStart + 14; spannable.setSpan(new UnderlineSpan(), indexPolicyStart, indexPolicyEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(getColor(R.color.theme)), indexPolicyStart, indexPolicyEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ClickableSpan() { @Override public void onClick(View widget) { Log.d(TAG, "TODO onClick.. Privacy Policy"); } }, indexPolicyStart, indexPolicyEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextView textViewTerms = (TextView) findViewById(R.id.sign_up_terms_text); textViewTerms.setText(spannable); textViewTerms.setClickable(true); textViewTerms.setMovementMethod(LinkMovementMethod.getInstance()); 
  • Agregue ID de programación a R.id
  • Un solo clic edittext
  • cómo quitar una cadena de arraylist de cadenas, ANDROID
  • EditText en ListView con windowSoftInputMode adjustPan
  • EditarTexto contenido dentro de ExpandableListView desaparecer al hacer clic en siguiente ExpandableListView encabezado
  • Android adjustpan no funciona después de la primera vez
  • SoftKeyboard abrir y cerrar escucha en una actividad en Android?
  • Necesita ayuda para centrar un EditText en un Layout Lineal
  • Generar Editar Texto Programaticamente en android
  • EditText se congela / no muestra texto al escribir
  • Editado Android enfoque automático
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.