Question

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;
            }
        }); 
Was it helpful?

Solution

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) {

            }

        });

OTHER TIPS

Try TextWatcher instead of onKeyListener

@Override
public void afterTextChanged(Editable s)
{
if (first_number_from.getText().toString().length() == 2)
{
     second_number_from.requestFocus();
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top