I have a TextView with html text and I need native copy/paste and clickable links.
I have used the next code, but when I use setMovementMethod(LinkMovementMethod.getInstance()); the native copy/paste stops to work.
If I change setMovementMethod(LinkMovementMethod.getInstance()) to ArrowKeyMovementMethod, the copy/paste works but the click links stops to work.
I don´t posted all code but setMovementMethod is used in updateDetail method.
Does someome can help me? Regards, Luiz
My code is:
textDetail = (TextView) view.findViewById(R.id.text_detail);
textDetail.setTextIsSelectable(true);
textDetail.setCustomSelectionActionModeCallback(new ActionMode.Callback()
{
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return true;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
return false;
}
});
protected void makeLinkClickable(SpannableStringBuilder strBuilder,
final URLSpan span) {
int start = strBuilder.getSpanStart(span);
int end = strBuilder.getSpanEnd(span);
int flags = strBuilder.getSpanFlags(span);
ClickableSpan clickable = new ClickableSpan() {
@Override
public void onClick(View view) {
}
////////
else {
///////////////
}
}
};
strBuilder.setSpan(clickable, start, end, flags);
strBuilder.removeSpan(span);
}
protected void setTextViewHTML(TextView text, String html) {
CharSequence sequence = Html.fromHtml(html);
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
URLSpan[] urls = strBuilder.getSpans(0, sequence.length(),
URLSpan.class);
for (URLSpan span : urls) {
makeLinkClickable(strBuilder, span);
}
text.setText(strBuilder);
}
public void updateDetail(String msg) {
setTextViewHTML(textDetail, msg);
textDetail.setMovementMethod(LinkMovementMethod.getInstance());
}