I guess this is not the best solution but it will do what you need.
1). Let your Activity
implement the View.OnTouchListener
and set it
yourButton.setOnTouchListener(this);
2). Create a class field of the CountDownTimer
type. I call it mTimer.
Add the following to the OnTouch()
method:
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
deleteChar();
break;
case MotionEvent.ACTION_MOVE:
/*--- no action required ---*/
break;
case MotionEvent.ACTION_UP:
mTimer.cancel();
break;
}
return false;
}
});
3). deleteChar()
method:
private void deleteChar(){
// set the desired interval. I'm gonna use 500ms before last char deletion.
mTimer = new CountDownTimer(9999999, 500) {
@Override
public void onTick(long millisUntilFinished) {
if(yourEditText.getText().toString().length() > 0){
String input = yourEditText.getText().toString();
input = input.substring(0, input.length()-1);
yourEditText.setText(input);
}
}
@Override
public void onFinish() {
}
};
mTimer.start();
}
The above example deletes last character of an EditText
with an interval of 1/2 sec. Use a Vibrator
object when you need it.
For sure this code can be optimized. This should just give you the basic idea how to perform what you are asking for.