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

                  }         

               }      

            });

        }

    }

    相关知识:

     

     

     

     

    最后实现效果:

     

     

     

  • 相关阅读:
    经典SQL语句大全
    MySQL数据库InnoDB存储引擎多版本控制(MVCC)实现原理分析
    Compilify——让你在浏览器中编译.NET代码
    Apache CouchDB 1.2.0新特性
    word转chm格式文档非常好用的转换工具
    ReSharper 6 Beta发布,商业.NET开发工具
    HTML.Next会给我们带来什么?
    在并行方法体中谨慎使用锁
    7款仿照Sinatra思路的.NET框架
    数据库工件的配置管理
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2645189.html
Copyright © 2011-2022 走看看