我有一个自定义 ListView 。带有按钮、TextView 等。它附加到 fragment 而不是 Activity 。用户可以与 ListView 进行交互,其中按钮文本和 TextView 发生变化。
ListView 的问题是,在我向上或向下滚动后,对 View 的所有更改都将重置为原始状态。
如何防止 ListView 重绘并保留 View 值?
PS:滚动期间触发的唯一事件是 ViewRoot 的触摸事件:触摸向上和触摸向下
菜单 fragment
public ItemsAdapter(Context context, List<MenuListItem> objects, String type, String date, ListView lstView) {
this.ctx = context;
this.listView = lstView;
this.itemsType = type;
this.items = objects;
this.date = date;
inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
ItemsAdapter itemsAdapter = new ItemsAdapter(getActivity(),itemList,itemType, dateOfMenu,lst);
lst.setAdapter(itemsAdapter);
void updateList(List<MenuFragment> newItems)
{
fragments.addAll(newItems);
pager.destroyDrawingCache();
this.notifyDataSetChanged();
indicator.notifyDataSetChanged();
}
最佳答案
列表适配器将您的数据(称为模型)连接到您的ListView
。该模型必须表示在任何时刻要在列表中显示的内容。
因此,捕获所有用户交互并将其存储在模型中非常重要,以便当 ListView
重新创建该列表项时,它可以显示该列表项发生的所有更新。
当用户单击按钮并编辑 TextView
时,您需要更新 MenuItemList
对象,然后在适配器上调用 notifyDataSetChanged()
。
关于java - ListView - 其 View 在滚动期间失去值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31062361/