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

                  }         

               }      

            });

        }

    }

    相关知识:

    最后实现效果:

  • 相关阅读:
    咖啡豆(JavaBean)•香
    SOC FPGA篇之 如何使用VNC 扩展桌面
    C指针地址运算
    nasm 指令学习
    CPL DPL RPL 及特权间的跳转
    ubuntu终端命令
    自动动手写操作系统 中 _disp_int 堆栈保护错误
    makefile 详解1
    [ 转载] Linux/Unix环境下的make和makefile详解2
    汇编指令: LGDT、LIDT、LLDT、LMSW、LOADALL、LOADALL286、LOCK、LODSB、LODSW、LODSD
  • 原文地址:https://www.cnblogs.com/changkai244/p/4110388.html
Copyright © 2011-2022 走看看