How can I make several clickable parts of text in TextView. Every clickable part must have his own action.
Just like Buttons and ImageViews we can add onClickListeners to TextViews by simply adding the attribute android:onClick="myMethod" to your TextView XML tag. The other way, TextView tv = (TextView) this.
you can use android.text.style.ClickableSpan
SpannableString ss = new SpannableString("Hello World"); ClickableSpan span1 = new ClickableSpan() { @Override public void onClick(View textView) { // do some thing } }; ClickableSpan span2 = new ClickableSpan() { @Override public void onClick(View textView) { // do another thing } }; ss.setSpan(span1, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ss.setSpan(span2, 6, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With