关闭

Android EditText password example

标签: androidlayoutbuttonencodingstringclass
726人阅读 评论(0) 收藏 举报
分类:

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();
 
}
 
});
 
 }
}





0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:239424次
    • 积分:2739
    • 等级:
    • 排名:第13123名
    • 原创:54篇
    • 转载:35篇
    • 译文:0篇
    • 评论:59条
    文章分类
    最新评论