I am developing an application that has 4 text fields for entering data into and I have come across a performance issue when moving focus from one to the other. When a field has a character entered into it I use the addTextChangedListener to monitor the text and move the focus to the next text field. This was working fine on versions of android before 4.1.1 but since testing on 4.1.1 there is a noticeable lag when you press a key before the focus appears in the next field. This means if the user types rapidly, key presses can be lost.
I have a simple app using the following code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
one = (EditText)findViewById(R.id.editText1);
two = (EditText)findViewById(R.id.editText2);
one.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
two.requestFocus();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
});
}
that highlights the issue. When run on a 4.0.4 based device everything is fine, but on 4.1.1 it takes a while to move the focus.
I have tested this on 2 different Samsung Galaxy s3's one with 4.0.4 and one with 4.1.1.
Has anyone else seen this?
Many thanks
Paul
I don't know if there is a solution for that problem... but I might have a "hack" that gives an alternative solution while the problem exists:
Put an EditText out of the screen. (I normally set it to the right of the right margin with a RelativeLayout).
Set onTouchListener
to your visible EditText (and set the EditText to not be clickable). The onTouchListener
should the focus to the hidden EditText.
On the hidden EditText set a addTextChangedListener
which for each character added or removed makes the proper changes on the visible EditTexts.
Example:
If I have 4 EditTexts for PIN with IDs: A
, B
, C
and D
and a EditText out of the screen with id hidden
:
Whenever I receive the first char on hidden
I write A
.
Whenever I receive the second char on hidden
I write B
.
Whenever I receive a delete on the second char of hidden
I delete on B
.
...
I'm doing something similar on one of my apps, without problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With