Android Clickablespan Not Calling Onclick

Android ClickableSpan not calling onClick

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

Android - Issue with clickableSpan and TextView

I figured out my question with this solution but if anyone had a better solution please let me know.

I set OnClickListener for my TextView and in the onClick event I get the parent of my TextView and check if the parent is clickable then perform parent onClick event and if not I recursively get the parent of the parent until I achieve to clickable parent. In this way, hashtags still are clickable with own actions and when clicking another part of the text the onClick event of the parent is performed.

here is the code of how I recursively find clickable parent:

private View getParentClickable(View view) {
try {
if (((View) view.getParent()).isClickable()) {
return (View) view.getParent();
} else {
return getParentClickable(((View) view.getParent()));
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

and then setOnClickListener for my view:

mTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View parent = getParentClickable(mTextView);
if (parent != null) parent.performClick();
}
});

The onClick() of ClickableSpan is not working for URLSpan?

Actually my senior figured out, we need to remove the original URLSpan before adding our own spans using setSpan()

    // The original URLSpan needs to be removed to block the behavior of browser opening
strBuilder.removeSpan(span);

Thanks Damian.

ClickableSpan OnClick is not being called for multi spans

I was using htmlTextView.getText() to create SpannableString and those words was links words in html text source so the click listener was not working
when i changed it to

SpannableString spannableString = htmlTextView.getText().ToString();

it works but i lost html design for text.



Related Topics



Leave a reply



Submit