java - why not display two picture in text? -
when type s in text1 corresponding picture appears in text2 when type g in text1 corresponding picture shown in text2, previous picture of s shown letter instead of picture. why that? why can't display 2 pictures? what's wrong?
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final edittext te1 = (edittext)findviewbyid(r.id.t1); final edittext te2 = (edittext)findviewbyid(r.id.t2); final button v = (button)findviewbyid(r.id.b1); v.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //imva.setimageresource(r.id.b1); te2.settext(" "); string t= te1.gettext().tostring(); char [] aa = t.tostring().tochararray(); (int = 0 ; < aa.length ; i++) { if (aa[i] == 's') { spannablestringbuilder builder = new spannablestringbuilder(te1.gettext()); { imagespan imagespan = new imagespan(getbasecontext(),r.drawable.a1); int pos = builder.tostring().indexof("s"); builder.replace(pos, pos + 1, "$"); builder.setspan(imagespan, pos, pos + 1,spannable.span_exclusive_exclusive); } while (builder.tostring().indexof("s") > -1); te2.settext(builder); } if (aa[i] == 'g') { spannablestringbuilder builder = new spannablestringbuilder(te1.gettext()); { imagespan imagespan = new imagespan(getbasecontext(),r.drawable.a2); int pos = builder.tostring().indexof("g"); builder.replace(pos, pos+ 1, "$"); builder.setspan(imagespan, pos, pos + 1,spannable.span_exclusive_exclusive); } while (builder.tostring().indexof("g") > -1); te2.settext(builder); } }
Comments
Post a Comment