Android EditText password example

strings.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>


    <string name="hello">Hello World, PasswordDemoActivity!</string>
    <string name="app_name">PasswordDemo</string>
<string name="lblPassword">Enter Your Password :</string>
    <string name="btn_submit">Submit</string>
</resources>


main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
    <TextView
        android:id="@+id/lblPassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/lblPassword"
        android:textAppearance="?android:attr/textAppearanceLarge" />
 
    <EditText
        android:id="@+id/txtPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword" >
 
        <requestFocus />
    </EditText>
 
    <Button
        android:id="@+id/btnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_submit" />
 
</LinearLayout>


Java 文件


package com.cjp.passworddemo;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;



public class PasswordDemoActivity extends Activity {
private EditText password;
 private Button btnSubmit;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
 
addListenerOnButton();
 
 }
 
 public void addListenerOnButton() {
 
password = (EditText) findViewById(R.id.txtPassword);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
 
btnSubmit.setOnClickListener(new OnClickListener() {
 
@Override
public void onClick(View v) {
 
 Toast.makeText(PasswordDemoActivity.this, password.getText(),
Toast.LENGTH_SHORT).show();
 
}
 
});
 
 }
}

Android EditText password example_第1张图片

Android EditText password example_第2张图片



你可能感兴趣的:(Android EditText password example)