android - How to get cursor position of EditText considering the html tags of the EditText html String -
please me in getting position of cursor in edittext considering html tags of string.
getselectionstart() giving cursor position in plain text, need position considering html tags of string.
i have implemented textwatcher on edittext text change. there in ontextchanged callback getting position considering plain text need html tags
i using this richedittext library edittext
pfb code. there nothing have done. cursor index not correct unable proceed.
public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); richedittext editpara_et=(richedittext )findviewbyid(r.id.editpara); string htmlstring="<p>i have edit text html string.</p>"; editpara_et.settext(html.fromhtml("<p>i have edit text html string.</p>")); mytextwatcher tw1 = new mytextwatcher(editpara_et,mainactivity.this,htmlstring); editpara_et.addtextchangedlistener(tw1); } class mytextwatcher implements textwatcher { public edittext edittext; context context; //constructor public mytextwatcher(edittext et,context ctx,string scriptwithparatags){ super(); edittext = et; context=ctx; } //some manipulation text public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after){ log.e("tc", "beforetc "+ s.subsequence(start, start + count).tostring()); } public void ontextchanged(final charsequence s, final int start, final int before, final int count) { int cursorindex=start+1; // index worng need index html tags /* eg:- stirng str= <p> have edittext html string </p> * if place cursor after 'i' cursor position should 6 if cursorindex start 1. getting 2 * * */ } }
}
thanks in advance.
Comments
Post a Comment