I have an EditText view in my Android app. I need “inner links” in it, this means that I need some buttons or span inside EditText and with onClick to this button I can do some actions (not redirect to web page).
I realized this buttons with ClickableSpan() like this
linkWord = "my link";
link = new SpannableString(linkWord);
cs = new ClickableSpan(){
private String w = linkWord;
@Override
public void onClick(View widget) {
wrd.setText(w);
}
};
link.setSpan(cs, 0, linkWord.length(), 0);
et.append(link);
For make this span clickable I used
et.setMovementMethod(LinkMovementMethod.getInstance());
“Inner links” works fine, but after using et.setMovementMethod() copy and paste items are disable on OnLongClick menu. And this is a problem, because I need “links” in EditText and copy text from this view in the same time.
I have idea to set in listener OnLongClickListener something like removeMovementMethod() for temporary disable “links” function and use menu with copy/paste and after coping text switch on setMovementMethod() method again. But I don’t know how to realize this.
Can you help me? You may be there are some another ways…
Thank you!
I solved this problem and may be this will be interesting for someone…
For clickable links inside EditText I used
in this case in longClick menu there are not copy/paste items.
For activate them I need back to normal EditText state, I can do it with:
After this method links will not work but appear normal longClick menu.
Therefore I added new item to the context menu and switched between this two options:
Also I registered EditText for context menu:
Have a hope that this will help someone!