hanggrian / socialview

Android TextView and EditText with hashtag, mention, and hyperlink support
http://hanggrian.com/socialview/
Apache License 2.0
323 stars 81 forks source link

SpannableString is not working with SocialAutoCompletTextView #78

Closed umerk44 closed 3 years ago

umerk44 commented 4 years ago

I've a SpannableString which I'm setting with .setText(spannableString) but it's updating spans. Same string would work with other views, like TextView, EditTextView.

AhmadIzaz commented 4 years ago

I am facing that too. Please fix this

Ddhams commented 4 years ago

Please fix this and Let me know

hanggrian commented 4 years ago

You'll have to elaborate what the issue is because I am unable to recreate it.

textView.setText(SpannableString.valueOf("Hello #there"))

Screenshot_1595360492

SotirisAtSeb commented 3 years ago

I have the same issue. What I want to do is apply a span to a text that is going to show up inside a SocialTextView. For example:

Username_here Hello @someone and good morning to @someone_else.

I want to make the "Username_here" part of the string be bold (which I can do via a Spannable) and the rest of the text (Hello @someone and good morning to @someone_else) to behave like it should since it is a SocialTextView (meaning being able to handle clicks on mentions and links).

Trying something like this:

val postTitle = item.customerInfo.name + " " + item.caption
var spannable = SpannableString(postTitle)

Timber.d("setting span from %d to %d (%s)", 0, item.customerInfo.name.length, spannable.toString())
spannable.setSpan(ForegroundColorSpan(Color.RED), 0, item.customerInfo.name.length, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)

binding.postTitle.text = spannable

doesn't make the item.customerInfo.name part to be red.

Any ideas what we can do to solve this issue?

hanggrian commented 3 years ago

@SotirisAtSeb this is quite different from the author's question.

What you can do at the moment is add your own TextWatcher with addTextListener. Put your code that spans red in afterChange. I will gladly continue the discussion and provide code sample if you're still having issues.

But back on topic, this issue is closed due to inactivity.

samuel2629 commented 3 years ago

Hi, i tried what you suggested about adding a Textwatcher and doing the manip in afterTextChanged, unfortunately it doesn't work ! I have the exact same problem that @SotirisAtSeb Any solution to it ? Thx

hanggrian commented 3 years ago

@samuel2629 post me your TextWatcher code snippet.