RecyclerView 中嵌套EditText绑定数据错乱

2020-01-10  本文已影响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);

  }

}

});
上一篇 下一篇

猜你喜欢

热点阅读