简体   繁体   中英

How to get the Edittext input type in Android when softkeyboard is displayed

How to get or know which Input type is been shown by the softkeyboard when the keyboard is displayed in an edittext in Android .Since I want to keep the memory of the input type of edittext even if the data get notified and changes the input type I want to maintain the inputtype in my local variable.

Ie my requirement is when I am manually changing the edit text to numeric and type something the edittext,Edittext sends an event to the server and data gets changed , after that when I press again to modify the value in the edit text ,the keyboard changes to alphabetic keyboard .This I want to avoid ,I want to remain the Softkeyboard to be in numeric,so I want to get the Input type displayed in the keyboard. So how can I get the Input type of Edittext displayed in the keyboard

String yourEditTextInputType;
        int editTextType = someEditText.getInputType();
        switch (editTextType) {
            case (InputType.TYPE_TEXT_FLAG_CAP_WORDS|InputType.TYPE_CLASS_TEXT): {
                yourEditTextInputType = "Name ";
            }
            break;
             case InputType.TYPE_CLASS_PHONE: {
                yourEditTextInputType = "Phone Number ";
            }
            break;
            case InputType.TYPE_CLASS_DATETIME: {
                yourEditTextInputType = "Date ";
            }
            break;
            case InputType.TYPE_CLASS_NUMBER: {
                yourEditTextInputType = "Number ";
            }
            break;
            case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS: {
                yourEditTextInputType = "Address ";
            }
            break;
            case (InputType.TYPE_TEXT_VARIATION_PASSWORD|InputType.TYPE_CLASS_TEXT): {
                yourEditTextInputType = "Password or Confirm Password ";
            }
            break;
            case (InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS|InputType.TYPE_CLASS_TEXT): {
                yourEditTextInputType = "Email ";
            }
            break;

            default: {
                yourEditTextInputType = "Field ";
            }
            break;
        }

      Log.d("TYPE",yourEditTextInputType);

      // Handle your logic of displaying keyboard , depending on input type

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM