开发者

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 n开发者_运维知识库umbers 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜