2

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

Pardeep Kr
  • 479
  • 2
  • 6
  • 25
  • As i notice my code is working fine on android nexus 5 . But on other devices like Samsung S6, sony xperia 4 moto E etc . its not working. – Pardeep Kr Feb 15 '16 at 06:14

1 Answers1

1

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

jayesh gurudayalani
  • 1,368
  • 1
  • 9
  • 14