Pregunta

Hello I have Difficulty to Change focus between two edit text. this task perform in Android 4.2 very well but Same task done in Samsung Duos Android 4.0.1 it's not working please give me Suggestions. Thank You

My Code is:

first_number_from.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (first_number_from.getText().length() == 2)
                    second_number_from.requestFocus();

                return false;
            }
        }); 
¿Fue útil?

Solución

You could add a text changed listener

first_number_from.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start,int before, int count)  {
                if(first_number_from.getText().toString().length() == 2) {
                    second_number_from.requestFocus();
                }
            }
            public void beforeTextChanged(CharSequence s, int start,
                            int count, int after) {}

            public void afterTextChanged(Editable s) {

            }

        });

Otros consejos

Try TextWatcher instead of onKeyListener

@Override
public void afterTextChanged(Editable s)
{
if (first_number_from.getText().toString().length() == 2)
{
     second_number_from.requestFocus();
}
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top