这次内容,我们就项目中添加商店名称的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);
  }

  这样就完成了这个功能,在文本框有内容输入时添加功能就会出现。

最新文章

  1. oracle 自增长序列
  2. Android中获取选择图片与获取拍照返回结果差异
  3. 火币网api的nodejs实现
  4. 我心中的核心组件(可插拔的AOP)~第二回 缓存拦截器
  5. 我刚知道的WAP app中meta的属性(转载)
  6. 关于inline-block的间隙问题
  7. 线性表链式存储方式的C语言实现
  8. MYSQL select ....outfile.....from.....
  9. css3学习文档
  10. Shell第三篇:基本语法
  11. iOS 上线因iPv6被拒,查询服务器是否支持iPv6,mac设置iPv6网络,手机测试iPv6
  12. [模板] 匈牙利算法&amp;&amp;二分图最小字典序匹配
  13. 富文本编辑器Quill(一)简单介绍
  14. VS2017 ASP.NET MVC 5.0 开部署问题汇总
  15. [Java Plasterer] Java Components 3:Java Enum
  16. 人生苦短之---认识Python
  17. C语言lseek()函数:移动文件的读写位置
  18. C#正则过滤HTML标签并保留指定标签的方法
  19. Cognos第三方用户认证(CustomJavaProvider)
  20. try...cath...finally中的return什么时候执行

热门文章

  1. linux上github的简单使用
  2. Eugene and an array(边界麻烦的模拟)
  3. N - Marriage Match II 网络流
  4. 利用css+js制作下拉列表
  5. Leetcode_45. 跳跃游戏 II
  6. spring源码解析--上
  7. CodeForces - 1209D Cow and Snacks 并查集
  8. LeetCode最长回文子串
  9. 设计模式之GOF23备忘录模式
  10. Spring整合Durid数据源