Android开发学习笔记:为动态添加的EditText控件绑定值改变监听事件
来源:互联网 发布:linux怎么访问网页 编辑:程序博客网 时间:2024/05/17 03:18
LinearLayout LP=new LinearLayout(context);final EditText editText=new EditText(context);//editText.setHeight(47);editText.setId(i);Log.i("当前添加的文本框ID:",String.valueOf(editText.getId()));editText.setHint(R.string.txthint);editText.setBackgroundResource(R.drawable.table_shape2);//设置自定义样式(使用的是drawable文件夹中的xml文件)/*设置EditText组件值改变监听事件*/editText.addTextChangedListener(new TextWatcher() {@Overridepublic void beforeTextChanged(CharSequence s, int start, int count, int after) {//Log.i("文本输入框值改变事件:",s.toString());}/** *值改变事件 * @param s 文本框输入的值 * @param start 输入的起始位置(索引) * @param before * @param count */@Overridepublic void onTextChanged(CharSequence s, int start, int before, int count) {//从内部类中访问本地变量editText; 需要被声明为最终类型(用final修饰)int editTxtId= editText.getId();LinearLayout editTextParent= (LinearLayout) editText.getParent();//获取当前编辑的文本输入框的父控件/** 获取当前文本编辑框所在的行对象(由于文本编辑框外嵌套了一个LinearLayout控件* 因此需要先获取文本边框的父控件)*/TableRow tr= (TableRow) editTextParent.getParent();Log.i("当前编辑行索引:",String.valueOf(tr.getId()));//设置第一列中CheckBox的状态为选中状态(注意布局时CheckBox外层嵌套一个LinearLayout组件)((CheckBox)((LinearLayout)tr.getChildAt(0)).getChildAt(0)).setChecked(true);}@Overridepublic void afterTextChanged(Editable s) { // Log.i("文本输入框值改变事件:",s.toString());}});LP.setBackgroundResource(R.drawable.table_shape);LP.addView(editText);
阅读全文
0 0
- Android开发学习笔记:为动态添加的EditText控件绑定值改变监听事件
- Android开发学习笔记:为动态添加的Spinner控件绑定数据源以及监听事件
- 为动态创建的控件添加事件绑定
- C#为控件动态添加事件绑定的时机
- C#开发学习笔记:动态绑定控件事件
- android开发中动态添加EditText控件的方法
- android EditText控件事件监听
- android EditText控件事件监听
- android EditText控件事件监听
- android EditText控件事件监听
- android EditText控件事件监听
- android editText动态改变事件
- android editText动态改变事件
- android editText动态改变事件
- android editText动态改变事件
- Android EditText 添加文本改变监听
- Edittext监听动态改变
- Android开发中给EditText控件添加TextWatcher监听实现对输入字数的限制
- Android.mk,安卓系统AOSP源码
- 自己编程实现strcat,strcpy,strlen ,strstr,strcmy
- nginx安装错误 ./configure: error: the HTTP rewrite module requires the PCRE library.
- centos7 mysql安装主从复制配置
- 一直处于Attempting to start Apache service...状态
- Android开发学习笔记:为动态添加的EditText控件绑定值改变监听事件
- (转)Java后端学习流程
- nginx安装
- 欢迎使用CSDN-markdown编辑器
- Leetcode_406 Queue Reconstruction by Height
- scratch克隆体编号
- 二叉排序树的理解
- linux在shell中获取时间
- Spring MVC中用@ResponseBody转json,字段为NULL或者为空不参加序列化方法汇总