2014年11月18日 星期二

Android開發零點起飛(第三章)筆記-android edittext password programmatically

Android開發零點起飛(第三章)筆記-android edittext password programmatically


 


資料來源:http://stackoverflow.com/questions/2586301/set-inputtype-for-an-edittext


mEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());


 


範例程式碼資料來源:http://blog.csdn.net/huluhong/article/details/39693911


 


public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState);
/* 載入main.xml Layout */
setContentView(R.layout.main);
/* findViewById()取得對象 */
et = (EditText) findViewById(R.id.mPassword);
cb = (CheckBox) findViewById(R.id.mCheck);
/* 設定CheckBox的OnCheckedChangeListener */
cb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
if (cb.isChecked()) {
/* 設定EditText的內容為可見的 */
et.setTransformationMethod(HideReturnsTransformationMethod
.getInstance());
} else {
/* 設定EditText的內容為隱藏的 */
et.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
}
});
}
















 






沒有留言:

張貼留言