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());   

                  }         

               }      

            });

        }

    }

    相关知识:

    最后实现效果:

  • 相关阅读:
    idoc 和 bapi 和 rfc 之间的区别
    ABAP--如何在ALV_Grid的函数中定义下拉列表
    ABAP
    关于SAP的视图类型
    程序中条用其他程序中已经存在的PERFORM
    通过SMATFORMS打印程序的参考模板
    字号尺寸大小对照表
    ubuntu 没有桌面 没有图标,只剩下壁纸
    latex ctex 的section不能写中文, /href
    System Verilog的概念以及与verilog的对比
  • 原文地址:https://www.cnblogs.com/dongweiq/p/4721314.html
Copyright © 2011-2022 走看看