Tuesday, 4 October 2011

Android - entering the password

Sometimes it is required to enter the password for a sign in service. In such case, the field of Password should be specially handler because not word should be shown, only few symbols (******).

The easiest thing to do in this case is modify the layout of the EditText component, enable the field of password as true. For example:

<EditText
    android:id="@+id/password"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:password ="true">
</EditText>


The another way to do it is set the inputType as textPassword.


<EditText
    android:id="@+id/password"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:inputType="textPassword">
</EditText>

For the java part, the code doesn't have to be different from any code to handle the EditText component. For example:

private EditText passwordEdit;

passwordEdit = (EditText) findViewById(R.id.password);

String password = passwordEdit.getText().toString();

No comments:

Post a Comment