文本视图中的数据在滚动列表视图时切换

Data in the text view toggling while scrolling list view

我有一个列表视图,其中每个 row.When 中都有一个文本和一个按钮 我单击按钮文本视图中的文本 changes.It 直到 now.But当我滚动列表视图时,文本更改为其默认值 text.Please 帮助如何在我滚动时在列表视图中单击按钮显示更改的文本。

我想要像上面的那样pic.But当我滚动列表视图时我变得像下面的图片

尝试以下步骤:

  1. 您应该使用 array/ArrayList 的默认文本,例如 plus,plus...,然后将此 array/ArrayList 传递给您的 CustomListAdapter。

  2. 在你的 CustomListAdapter 里面的 getView(): 从 array/ArrayList.

  3. 设置 textview 上的文本
  4. 单击按钮时:您应该更新 array/ArrayList 中的字符串,对应于单击的索引并调用 notifyDataSetChanged()。

已编辑答案 -

private void updateText(int position, String text) {
    arrayList.set(position, text);
    notifyDataSetChanged();
}

现在在两次按钮点击时调用上面的方法,例如

点击减号按钮 - updateText(position,"minus");

点击加号按钮- updateText(position,"plus");