zoukankan      html  css  js  c++  java
  • 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);
        }
      }
    }

           

  • 相关阅读:
    七 、linux正则表达式
    六、通配符
    Codeforces1099D.Sum in the tree(贪心)
    叮,出现!
    Codeforces1056E.Check Transcription(枚举+Hash)
    2018.11.25 AMC-ICPC 亚洲区域赛(焦作站)吊银
    Gym101889J. Jumping frog(合数分解+环形dp预处理)
    Gym101889E. Enigma(bfs+数位)
    Gym101889B. Buggy ICPC(打表)
    Codeforces1076F. Summer Practice Report(贪心+动态规划)
  • 原文地址:https://www.cnblogs.com/OuZeBo/p/4739607.html
Copyright © 2011-2022 走看看