Pardeep Kr
Pardeep Kr

Reputation: 497

How to continuously delete the characters on keypad backspace longpress in android

Generally we see that when we hold the BackSpace (Delete) key on a softKeypad in android , it keeps on deleting the characters in the EditText , until it becomes empty.

But in my case when i hold the backspace key on softkeypad ,it only deletes one character . I do not understand how to make it to continuously delete the characters .

Please Help

Upvotes: 2

Views: 1796

Answers (1)

jayesh gurudayalani
jayesh gurudayalani

Reputation: 1691

Sorry For late reply but may below code help you out

llRemoveOne.setOnTouchListener(this);

@Override
public boolean onTouch(View v, MotionEvent event) {
    if(v.getId() == R.id.llRemoveOne){
        Log.e("event",""+event.getAction());
        int currentPos = etMsg.getSelectionStart();
        if (currentPos > 0) {
            etMsg.setText(etMsg.getText().delete(currentPos - 1, currentPos));
            etMsg.setSelection(currentPos - 1);
        }
    }
    return true;
}

In Above code instead of putting logic inside onclick,I have puted that inside ontouch so that code will be executed until user release that key that will result in removal of single character one by one

Upvotes: 1

Related Questions