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());
}
}
});
}
}
相关知识:
最后实现效果:
最新文章
- java动态编译笔记
- php排序测试
- 网站重构-你了解AJAX吗?
- UML简易看懂
- ubuntu中安装Docker
- Android 布局之LinearLayout 子控件weight权重的作用详析(转)
- Microsoft SqlSever 数据库--软谋1
- git - 远程分支
- 201521123009 《Java程序设计》第11周学习总结
- 幂次法则power law
- C++中的const总结
- 学习Java的进度
- Disruptor学习笔记
- 线段树模板(HDU 6356 Glad You Came)
- Nodejs学习事件模块
- [TJOI2015]线性代数
- spring boot的静态资源加载
- Request[";";]接收的值有逗号(,)
- java 每一个对象都是根据hashCode区别的 每次返回不同的内存地址
- JFrog Artifactory
热门文章
- 实例讲解Silverlight 初始控件如何获得焦点
- django基础操作
- leetcode - [7]Binary Tree Preorder Traversal
- Java数组、集合
- Java理论学时第二节。课后作业。
- 中国移动物联网平台数据转发 c# 控制台程序
- Codeforces821B Okabe and Banana Trees 2017-06-28 15:18 25人阅读 评论(0) 收藏
- mac系统下安装Windows(7,8,10都一样的步骤)
- 前端开发 - HTML/CSS
- ASP.NET MVC 主要的四种过滤器和三种具体实现类