要想判断Checkbox是不是被选中,必须注册OnCheckedChangedListener。没什么难点,直接看代码。
package com.kevin.checkbox;
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.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
public class Main extends Activity {
private CheckBox chk_show;
private EditText et_password;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et_password = (EditText) findViewById(R.id.et_password);
chk_show = (CheckBox) findViewById(R.id.chk_show);
chk_show.setOnCheckedChangeListener(new CheckChangedListener());
}
class CheckChangedListener implements OnCheckedChangeListener{
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked){
// 设置EditText的内容为显示
et_password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
// 设置EditText的内容为隐藏
et_password.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
}
}
分享到:
相关推荐
android用CheckBox做为显示密码的复选框效果
1.页面引入layui.js和layui.css <!...<... <head>...link type=text/css rel=stylesheet href=common/layui/css/layui.css rel=external nofollow />...link type=text/css rel=stylesheet href=css/index.css ...
mfc LISTCONTROL控件上增加checkbox控 增加显示图标的功能,VC 6.0 MFC
一个WinForm的TreeView,某node的CheckBox初始状态为false,当双击这个node的checkbox时,会出现很奇怪的情况: 第一次双击checkbox,checkbox显示的状态会切换两次状态,unchecked-> checked-> unchecked,而...
类似淘宝店家定义SKU的界面功能!用于b2b
QTableView显示自定义CheckBox, 开发环境macos 10.13.1 Qt 5.9.1
JS控制checkboxJS控制checkbox
1、ListView item中加入checkbox后onListItemClick 事件无法触发。 原因:checkbox的优先级高于ListItem于是屏蔽了ListItem的单击事件。 解决方案:设置checkbox的android:focusable="false" 2、选择其中的...
结合LayUI的checkBox动态显示/禁止源码
一个ctreectrl控制checkbox显示、隐藏的代码,有兴趣可以关注下。声明:此程序来源于网络,经本人部分修改。
jquery checkbox 选中 取消 checkbox多选
带CheckBox的TreeView,可以在点击CheckBox或者TreeViewItem的时候改变勾选状态。
checkBox全选——jscheckBox全选——jscheckBox全选——jscheckBox全选——jscheckBox全选——jscheckBox全选——js
RecyclerView嵌入CheckBox带来的显示问题的解决办法
带checkbox的树 checkbox tree tree tree checkbox
C# combobox里面显示checkbox C# combobox里面显示checkbox
QTableView同时显示自定义Checkbox和文件图标,开发环境macos 10.13.1 Qt 5.9.1
一个以树形结构显示出来的checkbox,支持出三态的效果,类似于树形的结构