实现目标:

实现原理:

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

}

}

});

}

}

相关知识:

最后实现效果:

最新文章

  1. java动态编译笔记
  2. php排序测试
  3. 网站重构-你了解AJAX吗?
  4. UML简易看懂
  5. ubuntu中安装Docker
  6. Android 布局之LinearLayout 子控件weight权重的作用详析(转)
  7. Microsoft SqlSever 数据库--软谋1
  8. git - 远程分支
  9. 201521123009 《Java程序设计》第11周学习总结
  10. 幂次法则power law
  11. C++中的const总结
  12. 学习Java的进度
  13. Disruptor学习笔记
  14. 线段树模板(HDU 6356 Glad You Came)
  15. Nodejs学习事件模块
  16. [TJOI2015]线性代数
  17. spring boot的静态资源加载
  18. Request[""]接收的值有逗号(,)
  19. java 每一个对象都是根据hashCode区别的 每次返回不同的内存地址
  20. JFrog Artifactory

热门文章

  1. 实例讲解Silverlight 初始控件如何获得焦点
  2. django基础操作
  3. leetcode - [7]Binary Tree Preorder Traversal
  4. Java数组、集合
  5. Java理论学时第二节。课后作业。
  6. 中国移动物联网平台数据转发 c# 控制台程序
  7. Codeforces821B Okabe and Banana Trees 2017-06-28 15:18 25人阅读 评论(0) 收藏
  8. mac系统下安装Windows(7,8,10都一样的步骤)
  9. 前端开发 - HTML/CSS
  10. ASP.NET MVC 主要的四种过滤器和三种具体实现类