EditText et = (EditText) findViewById(R.id.mPassword); |
CheckBox cb = (CheckBox) findViewById(R.id.mCheck); |
/* 设定CheckBox的OnCheckedChangeListener */ |
cb.setOnCheckedChangeListener( new CheckBox.OnCheckedChangeListener() { |
public void onCheckedChanged(CompoundButton arg0, boolean arg1) { |
if (cb.isChecked()) { |
/* 设定EditText的内容为可见的 */ |
et.setTransformationMethod(HideReturnsTransformationMethod |
.getInstance()); |
} else { |
/* 设定EditText的内容为隐藏的 */ |
et.setTransformationMethod(PasswordTransformationMethod |
.getInstance()); |
} |
} |
}); |