recyclerView 中复用editview 时,添加addTextChangedListener事件每个item都触发了

将edittext.addTextChangedListener写在edittext.setOnFocusChangeListener hasFocus为true下面(即只有获取到焦点时才添加监听器)

et_vlaue.setOnFocusChangeListener(new View.OnFocusChangeListener() {
   @Override
   public void onFocusChange(View v, boolean hasFocus) {
       if(hasFocus){
           et_vlaue.addTextChangedListener(new TextWatcher() {
               @Override
               public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                   
               }

               @Override
               public void onTextChanged(CharSequence s, int start, int before, int count) {

               }

               @Override
               public void afterTextChanged(Editable s) {
                   //do something
               }
           });
       }
   }
});

你可能感兴趣的:(android,安卓)