hanggrian / socialview

Android TextView and EditText with hashtag, mention, and hyperlink support
https://hendraanggrian.github.io/socialview/
Apache License 2.0
322 stars 81 forks source link

setOnHashtagClickListener & setOnClickListener #96

Closed Mohammed2Mujalli closed 10 months ago

Mohammed2Mujalli commented 3 years ago

I sat two click listeners. One is called setOnClickListener and the other one is called setOnHashtagClickListener because I have two actions I wanna use. For example if he click on the hashtag I want the HashtagClickListener to take me to the Hash_Tag.classand when I click on the text it takes me to the FullMessgUser.class it self. But my problem is that when I click on the hashtag it uses both the click listeners. Please can you help me solving this issue image

ChristophyBarth commented 3 years ago

Hello @Mohammed2Mujalli, have you resolved this. If no, can you explain better so I can understand?

hanggrian commented 3 years ago

This feature could be implemented properly, as discussed in this thread. But I'm just not sure how many people would find it useful. I'll keep this issue open for more feedback.

In the meantime, you could use this simple workaround below. Note that the TextView itself still shouldn't be clickable, only the rest of the text are.

textView.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void afterTextChanged(Editable s) {
        s.setSpan(new ClickableSpan() {
            @Override
            public void onClick(@NonNull View widget) {
                // do something
            }

            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
            }
        }, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
});
hanggrian commented 10 months ago

Closed for inactivity.