zoukankan      html  css  js  c++  java
  • 打勾显示输入的密码 --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());   

                  }         

               }      

            });

        }

    }

    相关知识:

    最后实现效果:

  • 相关阅读:
    Linux下Java安装与配置
    HYSPLIT模式简介及在线平台使用
    HYSPLIT模式简介及单机版使用图文教程
    有关气象类资料数据下载网址
    Excel图表编程应用大全(2):图表编程基础
    当装系统时遇到“选中的磁盘采用GPT分区形式”
    SQL函数
    Centos6.7 Redis3.2.8的主从搭建
    Centos 6.7 中 Redis-3.2.8的安装
    Mysql innodb_buffer_pool_size的研究
  • 原文地址:https://www.cnblogs.com/dongweiq/p/4721314.html
Copyright © 2011-2022 走看看