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

3

7

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)

Regardant answered 27/8, 2013 at 16:50 Comment(1)
have you found a solution?Mossbunker
E
3

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

Euchromatin answered 27/8, 2013 at 17:54 Comment(0)
D
2

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

Docilu answered 27/8, 2013 at 17:47 Comment(0)
Q
1

In this line of code you can do whatever you want when the backspace button is pressed. Something like editText.setText("");

editText.setOnKeyListener(new OnKeyListener() {                 
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        //You can identify which key pressed buy checking keyCode value with KeyEvent.KEYCODE_
         if(keyCode == KeyEvent.KEYCODE_DEL){  
             //this is for backspace
             }
    return false;       
        }
});
Qua answered 27/8, 2013 at 17:49 Comment(1)
Is there a way to work with this in software keyboard?Help

© 2022 - 2024 — McMap. All rights reserved.