eatwhatApp开发实战(十三)
2024-09-04 06:07:17
这次内容,我们就项目中添加商店名称的EditText进行修改,让添加按钮随着edittext的内容而改变。
上代码,首先是xml文件上对两个控件的修改:
<RelativeLayout
android:id="@+id/et_relative"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/addshop_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:hint="店名"/>
<TextView
android:id="@+id/add_shop_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:focusable="true"
android:onClick="addShop"
android:textSize="18sp"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:text="@string/add_shop_btn_text"
android:visibility="gone"/>
</RelativeLayout>
接下来定义,并初始化对应控件:
private TextView add_shop_text; // 初始化控件 add_text
add_shop_text = (TextView) findViewById(R.id.add_shop_text);
// 初始化控件addshop_EditText
addshop_et = (EditText) findViewById(R.id.addshop_et);
//edittext设置监听
addshop_et.addTextChangedListener(new TextChanged());
设置edittext的修改文本内容监听addTextChangedListener();
class TextChanged implements TextWatcher{ @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) {
// TODO Auto-generated method stub } @Override
public void afterTextChanged(Editable s) { }
}
在afterTextChanged(Editable s)方法中写对应逻辑:
if(s != null && !"".equals(s.toString())){
add_shop_text.setVisibility(View.VISIBLE);
}else {
add_shop_text.setVisibility(View.INVISIBLE);
}
这样就完成了这个功能,在文本框有内容输入时添加功能就会出现。
最新文章
- oracle 自增长序列
- Android中获取选择图片与获取拍照返回结果差异
- 火币网api的nodejs实现
- 我心中的核心组件(可插拔的AOP)~第二回 缓存拦截器
- 我刚知道的WAP app中meta的属性(转载)
- 关于inline-block的间隙问题
- 线性表链式存储方式的C语言实现
- MYSQL select ....outfile.....from.....
- css3学习文档
- Shell第三篇:基本语法
- iOS 上线因iPv6被拒,查询服务器是否支持iPv6,mac设置iPv6网络,手机测试iPv6
- [模板] 匈牙利算法&;&;二分图最小字典序匹配
- 富文本编辑器Quill(一)简单介绍
- VS2017 ASP.NET MVC 5.0 开部署问题汇总
- [Java Plasterer] Java Components 3:Java Enum
- 人生苦短之---认识Python
- C语言lseek()函数:移动文件的读写位置
- C#正则过滤HTML标签并保留指定标签的方法
- Cognos第三方用户认证(CustomJavaProvider)
- try...cath...finally中的return什么时候执行