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
How to Make a Phone Number Clickable on an iPhone or Android Phone to Make a Call in HTML
How to Handle App Lifecycle with Flutter (On Android and iOS)
What Are The Semantics of Withvaluebackreference
Need Some Clarification About Beta/Alpha Testing on The Developer Console
Fcm Remote Notifications Payload for iOS and Android
Mat (Eclipse Memory Analyzer) - How to View Bitmaps from Memory Dump
Listview: Textview with Linkmovementmethod Makes List Item Unclickable
Air 3 Native Extensions for Android - Can I/How to Include 3Rd Party Libraries
Using Numberpicker Widget with Strings
How to Style Appcompat-V7 Toolbar Like Theme.Appcompat.Light.Darkactionbar
Making Sense of Android Meta-Viewport Scaling: What Am I Missing
Attempt to Reopen an Already-Closed Object SQLitedatabase