Im trying to make certain substrings of a SpannableString editable.
Im able to identify and make clickable any substring that matches my criteria using matcher.find()
and ClickableSpan()
Im also able to make the substring editable using
myTxtView.setFocusable(true);
myTxtView.setEnabled(true);
myTxtView.setClickable(true);
myTxtView.setFocusableInTouchMode(true);
myTxtView.setCursorVisible(true);
myTxtView.setInputType(InputType.TYPE_CLASS_TEXT);
myTxtView.requestFocus();
The problem is the entire textview becomes editable, not just the substrings that where matched.
Here is the code
final SpannableString hashText = new SpannableString(myTxtView.getText().toString());
while (matcher2.find()) {
//find and match strings
hashText.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
//do something on click
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(Color.parseColor("#A8000000"));
ds.setUnderlineText(true);
}
},matcher2.start(),matcher2.end(),1);
}
myTxtView.setText(hashText);
myTxtVIew.setMovementMethod(LinkMovementMethod.getInstance());
myTxtView.setFocusable(true);
myTxtView.setEnabled(true);
myTxtView.setClickable(true);
myTxtView.setFocusableInTouchMode(true);
myTxtView.setCursorVisible(true);
myTxtView.setInputType(InputType.TYPE_CLASS_TEXT);
myTxtView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
I've played around a bit with Editable.Factory()
with no success. Not sure how or if that is applicable to my case.
You need to use
ClickableSpan
to perform the things you want, here is some codeSnippet which will help youtake a reference from androidgig.com
Output