[안드로이드,Android] 패스워드,Password 보이기 및 가리기

2013. 1. 4. 11:09Mobile/Android



반응형

public class MainActivity extends Activity {
   

    EditText mEtPW;
    CheckBox checkbox;


 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // EditText
        mEtPW= (EditText) findViewById(R.id.etpw);
        // Checkbox
        checkbox= (CheckBox) findViewById(R.id.checkbox);
            
        // 체크 박스 체크 유무.
        checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
           
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // 체크박스가 체크 안될 경우.
                if (!isChecked) {
                        // 패스워드가 보임 (ex . 1234)       

                mEtPW.setTransformationMethod(PasswordTransformationMethod.getInstance());
                } else {
                        // 패스워드 안보임 (ex. ****)

                mEtPW.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }
            }
        });
    }

반응형