Search code examples
androidtextview

Android ClickableSpan not calling onClick


I am creating a ClickableSpan, and it is displaying properly with the proper text underlined. However, the clicks are not registering. Do you know what I am doing wrong???

Thanks, Victor

Here is the code snippet:

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);

Solution

  • Have you tried setting the MovementMethod on the TextView that contains the span? You need to do that to make the clicking work...

    tv.setMovementMethod(LinkMovementMethod.getInstance());