Reputation: 13045
I have a kind of quantity field with +
and -
buttons.
When the user clicks on those buttons it increments or decrements an integer inside an EditText
. I use an EditText
and not a TextView
because the user can also edit the field manually with the keyboard.
When the user long-clicks, I start a thread which updates the EditText
quickly, the thread is stopped when the user releases the button. The update is doing well but my app is getting laggy because of the EditText
listeners.
I got a lot of log like that :
05-22 12:56:21.625: W/IInputConnectionWrapper(15137): getTextAfterCursor on inactive InputConnection
05-22 12:56:21.635: W/IInputConnectionWrapper(15137): getTextBeforeCursor on inactive InputConnection
05-22 12:56:21.635: W/IInputConnectionWrapper(15137): getTextAfterCursor on inactive InputConnection
05-22 12:56:21.635: W/IInputConnectionWrapper(15137): getTextBeforeCursor on inactive InputConnection
I managed to avoid the freezes by setting to null the KeyListener
before starting the thread
editText.setKeyListener(null)
but I'm not very pleased with that solution because it changes the soft keyboard input type. Each time the user clicks on the buttons, the soft keyboard change from number input type to standard input type.
Is there another way to avoid freezes when spamming an EditText
?
Upvotes: 0
Views: 661
Reputation: 5472
Well you can try something like this..
NumberKeyListener keyListener = new NumberKeyListener() {
public int getInputType() {
return InputType.TYPE_CLASS_NUMBER;
}
@Override
protected char[] getAcceptedChars() {
return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ':', '-', ',' };
}
};
and then set
editText.setKeyListener(keyListener);
This will make sure you get number input type..
hope this helps..
Upvotes: 1