Android筆記-5-EditText密碼和Checkbox二選一

來源:互聯網
上載者:User

標籤:

EditText密碼:明文和密文

密文:

 1 public class MainActivity extends Activity { 2        3       private EditText password = null; 4       @Override 5       protected void onCreate(Bundle savedInstanceState) { 6           super.onCreate(savedInstanceState); 7           setContentView(R.layout.activity_main); 8            9          this.password = (EditText) super.findViewById(R.id.pwdEdittext);10        //設定為密文11          MainActivity.this.password.setTransformationMethod(PasswordTransformationMethod.getInstance()); 12         13      }14  15     @Override16      public boolean onCreateOptionsMenu(Menu menu) {17          // Inflate the menu; this adds items to the action bar if it is present.18          getMenuInflater().inflate(R.menu.main, menu);19          return true;20      }21  }

明文密文切換(Checkbox切換):

public class MainActivity extends Activity {        private EditText password = null;    private CheckBox show = null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                this.password = (EditText) super.findViewById(R.id.pwdEdittext);        MainActivity.this.password.setTransformationMethod(PasswordTransformationMethod.getInstance());        this.show = (CheckBox) super.findViewById(R.id.display_checkBox);        this.show.setOnClickListener(new OnclickListenerlmp());    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }    public void register(View view){                Intent intent = new Intent();        intent.setClass(this, RegisterActivity.class);        this.startActivity(intent);            }    private class OnclickListenerlmp implements OnClickListener{        @Override        public void onClick(View v) {            // TODO Auto-generated method stub            if(MainActivity.this.show.isChecked()){                //設定為明文顯示                MainActivity.this.password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());            }            else{                //設定為密文顯示                MainActivity.this.password.setTransformationMethod(PasswordTransformationMethod.getInstance());            }        }    }}

Checkbox二選一

public class RegisterActivity extends Activity {  private CheckBox choose1 = null;  private CheckBox choose2 = null;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_register);  this.choose1 = (CheckBox) super.findViewById(R.id.sex_checkBox1);  this.choose2 = (CheckBox) super.findViewById(R.id.sex_checkBox2);  }  @Override  public boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.register, menu);    return true;  }  public void choose(View view){    if(RegisterActivity.this.choose1.isChecked()){    choose2.setChecked(false);   }    else{      choose1.setChecked(false);    }  }}

 

       

Android筆記-5-EditText密碼和Checkbox二選一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.