Android ClickableSpan not calling onClick

Victor Grazi picture Victor Grazi · Dec 27, 2011 · Viewed 33.9k times · Source

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

Answer

Marc Attinasi picture Marc Attinasi · Dec 29, 2011

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