Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backspace to delete whole word (entity) instead of each letter/character

In my app, I have an edittext which will contain a user (brought from db). There is the possibility that more than a user be present inside the edittext in the following manner : UserX, UserY, UserZ

I want to make the backspace of the virtual keyboard function in such a way that upon click, it deletes the whole user, rather than each character.

Any hints how to do this? As I did not find anything upon my searches. (perhaps I was using wrong keywords)

like image 384
tony9099 Avatar asked Aug 27 '13 16:08

tony9099


2 Answers

I suggest you use a SpannableString.Here is a complete guide : link. Good luck !

like image 110
bashizip Avatar answered Oct 21 '22 19:10

bashizip


You need to look into the listeners for editing text.

Then, when the user presses backspace, delete till you find a space by maybe using a lastIndexOf() method.

So, you getText() from EditText, you substring() it till the last space character, take that substring and set it as the new text

like image 33
An SO User Avatar answered Oct 21 '22 20:10

An SO User