美文网首页
RecyclerView 中嵌套EditText绑定数据错乱

RecyclerView 中嵌套EditText绑定数据错乱

作者: 老北瓜 | 来源:发表于2020-01-10 15:08 被阅读0次

    就这样
    在 onBindHolder() 里面 对将要处理的 EditText 这样处理;

    holder.mRouteView.mDestinationEt.setText(item.getDestination());
    
    TextWatcher desWatcher =new NewWatcher() {
    
    @Override
    
        public void afterTextChanged(Editable s) {
    
    if (holder.mRouteView.mDestinationEt.hasFocus()) {
    
    if (mRouteListener !=null)
    
    mRouteListener.getDestination(position, holder.mRouteView.mDestinationEt.getText().toString());
    
            }
    
    }
    
    };
    
    holder.mRouteView.mDestinationEt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    
    @Override
    
        public void onFocusChange(View v, boolean hasFocus) {
    
    if (hasFocus) {
    
            holder.mRouteView.mDestinationEt.addTextChangedListener(desWatcher);
    
     }else {
          holder.mRouteView.mDestinationEt.removeTextChangedListener(desWatcher);
    
      }
    
    }
    
    });
    

    相关文章

      网友评论

          本文标题:RecyclerView 中嵌套EditText绑定数据错乱

          本文链接:https://www.haomeiwen.com/subject/jaapactx.html