The constant value of the Edittext input parameter does not match

In android xml im file using editext as

<EditText
  android:id="@+id/email"
  android:layout_width="fill_parent"
  android:layout_height="33dp"
  android:inputType="textEmailAddress"
  android:hint="Enter your mail id" />

In java file while checking this editext.

if(editextobj.getInputType()==InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS){

}

or

if(getInputType()==(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)){

}

this condition does not work because it editextobj.getInputType()returns 33, while the developer's document gives a constant TYPE_TEXT_VARIATION_EMAIL_ADDRESSas 32

How to check input type programmatically?

+4
source share
4 answers

There is nothing wrong with the code. 32 is reserved for TYPE_TEXT_VARIATION_EMAIL_ADDRESS . It is also a flag, so you should check it like this. See InputType for details (top class overview).

if(editextobj.getInputType() & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS == 1){

}
+2
source

, :

if ( ( editextobj.getInputType() & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) != 0)
{
     // This is an email address!
}
+2

:
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS : 32.
InputType.TYPE_CLASS_TEXT: 1.

(|) . :

Decimal: 32 | 1 results in 33 | Binary: 100000 | 1 leads to 100001, which is 33 decimal.

editextobj.getInputType() value is 33

+1
source

Try the following:

if(editextobj.getInputType() == (InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS + 1)) {....}
0
source

All Articles