- package sucre.android;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.method.HideReturnsTransformationMethod;
- import android.text.method.PasswordTransformationMethod;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.EditText;
-
-
-
-
-
-
-
-
-
- public class EX03_22 extends Activity {
- private EditText mEditText;
- private CheckBox mCheckBox;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- mEditText = (EditText)findViewById(R.id.mEditText);
- mCheckBox = (CheckBox)findViewById(R.id.mCheckBox);
- mCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if(mCheckBox.isChecked()){
- mEditText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
- mCheckBox.setText("隐藏密码");
- }else{
- mEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
- mCheckBox.setText("显示密码");
- }
- }
- });
- }
- }
本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/746611,如需转载请自行联系原作者