• Android笔记-5-EditText密码和Checkbox二选一


    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     @Override
    16      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);
        }
      }
    }

           

  • 相关阅读:
    使用ATL开发ActiveX控件
    [Silverlight]AutoCompleteBox控件的一个Bug?
    [Silverlight]一个简单的GroupBox控件
    WCF安全之ASP.NET兼容模式
    Mysql 性能优化记录
    【Python+Django+Pytest】数据库异常pymysql.err.InterfaceError: (0, '') 解决方案
    Django在使用logging日志模块时报错无法操作文件 logging error Permission Error [WinError 32]
    isinstance 判断一个对象属于或不属于多种数据类型
    CentOS 系统 查看 cpu核数
    我踩过的python的坑
  • 原文地址:https://www.cnblogs.com/OuZeBo/p/4739607.html
Copyright © 2020-2023  润新知