监听多个EditText,只有当它们都有输入后,相应Button才能被点击
来源:互联网 发布:淘宝怎么排名靠前 编辑:程序博客网 时间:2024/05/24 06:48
这篇文章是网上的资源。
public class SomeMonitorEditText implements TextWatcher { private Button button; private EditText[] text; public void SetMonitorEditText(final Button button, final EditText... text) { this.button = button; this.text = text; for (int i = 0; i < text.length; i++) { if (text[i] != null) { text[i].addTextChangedListener(SomeMonitorEditText.this); } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub for (int i = 0; i < text.length; i++) { if (text[i].length() == 0) { button.setBackgroundResource(R.drawable.graylong_btn); button.setEnabled(false); return;//这句代码值两千万 } else { button.setBackgroundResource(R.drawable.red_btn); button.setEnabled(true); } } }}
主函数的布局文件就不写了,见图片
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EditText et1 = (EditText) findViewById(R.id.et1); EditText et2 = (EditText) findViewById(R.id.et2); EditText et3 = (EditText) findViewById(R.id.et3); EditText et4 = (EditText) findViewById(R.id.et4); Button btn = (Button) findViewById(R.id.btn); new SomeMonitorEditText().SetMonitorEditText(btn, et1, et2, et3, et4); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "被点击了", Toast.LENGTH_SHORT).show(); } }); }}
阅读全文
0 0
- 监听多个EditText,只有当它们都有输入后,相应Button才能被点击
- 当UITextField有内容时,button才能被点击
- 监听多个EditText,满足条件后Button才可以点击
- listViewitem和上面的多个button都有点击事件
- android多个button监听点击事件-法二
- UITextField只有当有字符输入后,键盘右下角的搜索/返回/done/等等键才可
- 多个Button监听
- EditText:监听输入后的操作
- 自定义一个输入框点击搜索后可以保存记录,搜索有取消,只有输入文字后在出现
- 监听EditText内容变化设置Button是否可点击
- 一行代码监听EditText变化改变Button可否点击
- 解决EditText点击两次才能输入的问题
- 解决popupWindow 中EditText点击两次才能输入的问题
- android - EditText监听输入多少个字符
- 多个editText监听事件
- 多个button共用监听
- Android 多个Edittext不为空,Button才可点击的方法
- 多个button点击崩溃
- ANSI Common Lisp译本笔记7
- kylin官方给出的优化 以及各个步骤容易出现的问题
- 获取定位,获取屏幕
- HDU
- spring cloud踩坑日志(3)-多环境配置文件用法
- 监听多个EditText,只有当它们都有输入后,相应Button才能被点击
- 3.打包压缩命令总结
- 马云:阿里巴巴必须成为国家和世界创新的发动机
- nginx https
- input radio
- HTML5跨应用的使用体验
- 前端代码优化基本方法
- FFmpeg在iOS上完美编译
- Session和Cookie总结