android - How to add text in between words in edittext when a button is pressed -
i cannot figure out how add space between every word user types edittext still beginner. have typed obvious code below.
findviewbyid(r.id.button).setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { edittext edittext = (edittext) findviewbyid(r.id.edittext); edittext edittext2 = (edittext) findviewbyid(r.id.edittext2); edittext2.settext(???); } });
in case isn't obvious, there seperate edittexts. user types edittext
, trying text "come out" in edittext2
spaces added.
edit: here finished code if wants it. added bit says how many spaces it's added.
edittext edittext = (edittext) findviewbyid(r.id.edittext); textview edittext2 = (textview) findviewbyid(r.id.edittext2); string str = edittext.gettext().tostring(); str = str.replace(" ", " "); edittext2.settext(str); string stre = edittext2.gettext().tostring(); string string = edittext.gettext().tostring(); int length = string.length(); int lengthy = stre.length(); int finale = lengthy - length; textview result = (textview) findviewbyid(r.id.textresult); result.settext( finale + " spaces have been added.");
would work ? sorry can't test, on phone.
edittext2.settext(edit text.gettext().tostring().replace all(" ", " "));
Comments
Post a Comment