• Textchangedlistener的用法


     1  searchet.addTextChangedListener(new TextWatcher() {
     2             @Override
     3             public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
     4             }
     5 
     6             @Override
     7             public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
     8                 Toast.makeText(SearchActivity.this, charSequence, Toast.LENGTH_SHORT).show();
     9                 switch (charSequence.toString()){
    10                     case "":searchtv.setText("取消");break;
    11                     default:searchtv.setText("搜索");
    12 
    13                 }
    14 
    15             }
    16 
    17             @Override
    18             public void afterTextChanged(Editable editable) {
    19 
    20             }
    21         })

    文字改变该方法就会调用,所以是个比较好用的方法.

    需要注意的是 CharSequence text,即是显示的文字信息,:利用这个如下可以查看

    Toast.makeText(SearchActivity.this, charSequence, Toast.LENGTH_SHORT).show();

    searchet.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    Toast.makeText(SearchActivity.this, charSequence, Toast.LENGTH_SHORT).show();
    switch (charSequence.toString()){
    case "":searchtv.setText("取消");break;
    default:searchtv.setText("搜索");

    }

    }

    @Override
    public void afterTextChanged(Editable editable) {

    }
    });
  • 相关阅读:
    Web实现大文件分片上传的方法
    kinova环境配置
    c++ stl list
    echarts饼图
    js函数
    飞浆测试日志
    IfcRevolvedAreaSolidTapered
    matlab一元二次方程求根
    运行日志
    常用的sql
  • 原文地址:https://www.cnblogs.com/imqsl/p/6696469.html
Copyright © 2020-2023  润新知