• 3.22 打勾显示输入的密码 EditText与setTransformationMethod


    实现目标:

    实现原理:

    为CheckBox添加一个监听器事件;

    实现的源码:

    package edu.cquptzx.showPassword;

     

    import android.app.Activity;

    import android.os.Bundle;

    import android.text.method.HideReturnsTransformationMethod;

    import android.text.method.PasswordTransformationMethod;

    import android.widget.CheckBox;

    import android.widget.CompoundButton;

    import android.widget.EditText;

     

    publicclass ShowPasswordActivity extends Activity {

        private EditText edittext;

        private CheckBox checkbox; 

        /** Called when the activity is first created. */

        publicvoid onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            /*find the object by IDs .*/

           

            edittext = (EditText) findViewById(R.id.et);

            checkbox = (CheckBox) findViewById(R.id.cb);

           

            /* add a listener to the CheckBox */

            checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()

            {

               publicvoid onCheckedChanged(CompoundButton buttonView,boolean isChecked)

               {

                  if(checkbox.isChecked())

                  {

                      /* show the password*/

                      edittext.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

                  }

                  else

                  {

                      /* hide the password */

                     edittext.setTransformationMethod(PasswordTransformationMethod.getInstance());   

                  }         

               }      

            });

        }

    }

    相关知识:

     

     

     

     

    最后实现效果:

     

     

     

  • 相关阅读:
    一、单一职责原则
    四、接口隔离原则
    彼得·林奇的25条黄金规则
    程序员的四个境界
    VS2008开发.NET 2.0的项目时,可用的C#3.0语言特性一览表
    Linq试用问题总结
    SQL Server 2000中修改数据库COLLATE一例
    SQL Tip:将SP生成的结果集Insert到另一Table中
    OOAD读书笔记(一):什么是好的软件?
    成功创业的8个关键点
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2645189.html
Copyright © 2020-2023  润新知