安卓EditText监听内容变化

       编辑框EditText在开发过程中还是很常用的 , 而有的时候我在想 , 如何实时的获取编辑框里的内容呢 ? 例如 在商品列表中 , 我想在用户输入关键字的时候 自动匹配结果  然后实时的展示出来 , 这就需要用到EditText的一个内容观察者 TextWatcher监听了


[java]  view plain  copy
et_money.addTextChangedListener(new TextWatcher() {
        
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // 输入的内容变化的监听
            Log.e("输入过程中执行该方法", "文字变化");
        }
        
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // 输入前的监听
            Log.e("输入前确认执行该方法", "开始输入");
            
        }
        
        @Override
        public void afterTextChanged(Editable s) {
            // 输入后的监听
            Log.e("输入结束执行该方法", "输入结束");
            
        }
    })

猜你喜欢

转载自blog.csdn.net/fdgfgfdgfd/article/details/80462244