目标:单击事件的运用
checkBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (checkBox.isChecked()) {
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
主要使用的是setTransformationMethod方法,参数需要一个TransformationMethod实例,通过工厂模式返回。
依靠HideReturnsTransformationMethod类的实例返回明文,PasswordTransformationMethod类的实例返回密文。