代码之家  ›  专栏  ›  技术社区  ›  Rgfvfk Iff

将编辑文本保留在回收器视图中[重复]

  •  1
  • Rgfvfk Iff  · 技术社区  · 7 年前

    我有一个 recycler view 对于两种视图类型,1只是 textview 另一个只是 edittext 是的。这个 编辑文本 始终位于文本下方的回收器视图的底部。当我输入edittext并向上滚动时, 编辑文本 是可回收的,但是否可以防止它被回收,并允许用户在向上滚动后继续键入?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Udit    7 年前

    如果您需要禁用视图回收(并且您了解权衡),那么最好使用linearlayout并在运行时向其添加视图。

        2
  •  1
  •   Karan Rana    7 年前

    如果要使用“回收站”视图并保留输入的文本,则必须使用文本观察程序( https://developer.android.com/reference/android/text/TextWatcher )并且需要将更改的文本保存到集合对象中。

    editTextInstance.addTextChangedListener(new TextWatcher() {
    
       @Override
       public void afterTextChanged(Editable s) {}
    
       @Override    
       public void beforeTextChanged(CharSequence s, int start,
         int count, int after) {
       }
    
       @Override    
       public void onTextChanged(CharSequence s, int start,
         int before, int count) {
                 collcectionInstance.get(position).setName(s);
       }
      });
    
    推荐文章