user872423
user872423

Reputation: 21

Android EditText soft keyboard question

I have EditText what should get user input for airplane seat number (like 17G, 5A etc) Problem is then I set EditText input type to text, it always open up soft keyboard with text. But my input always starts with numbers, so user have to switch keyboard to numbers and back all the time. Question is how to setup keyboard to open text keyboard on part where numbers located? I try'd to put android:inputType="numeric" but it just open numeric keyboard and it is not possible to enter any text after.

Upvotes: 2

Views: 561

Answers (1)

Kunami
Kunami

Reputation: 237

Since seat number (your example) will have different number count, it's kinda difficult guessing when to change from one keyboard type to another.

Otherwise, you can change EditText input type programmatically like this:

((EditText) mView.findViewById(R.id.et_seat_number)).addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable editable) {

            EditText etSeatNumber = (EditText) mView.findViewById(R.id.et_seat_number);
            if(editable.length() > 2)
                etSeatNumber.setInputType(InputType.TYPE_CLASS_NUMBER);
            else{
                etSeatNumber.setInputType(InputType.TYPE_CLASS_TEXT);
            }
        }
    });

Also you can use softkeyboard IME options to change keyboard input type. https://stackoverflow.com/a/40526750/6672482

Upvotes: 1

Related Questions