这是我的适配器的getView() - 使用View Holder模式非常简单的实现:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Exercise exercise = mList.getItem(position);
ViewExerciseHolder viewExerciseHolder;
if(convertView == null) {
viewExerciseHolder = new ViewExerciseHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.item_view, parent, false);
...
viewExerciseHolder.inputsLayout = (LinearLayout) convertView.findViewById(R.id.inputs);
convertView.setTag(viewExerciseHolder);
} else {
viewExerciseHolder = (ViewExerciseHolder) convertView.getTag();
}
for (int i=0; i<exercise.nbSeries; i++) {
ItemExerciseNbRepWeightView view = new ItemExerciseNbRepWeightView(getContext());
view.setNbRep(exercise.nbReps);
view.setWeight(exercise.weight);
...
viewExerciseHolder.inputsLayout.addView(view);
}
}
问题是 inputsLayout :添加的数据不正确,在滚动期间这些数据发生了变化......
感谢您的帮助!
答案 0 :(得分:1)
嵌套的Layout
被回收,这意味着它可能包含在之前调用getView()
时添加的视图。您必须清除之前添加的所有View
的回收'inputsLayout'。
执行此操作的一种方法是致电removeAllViews()
。
答案 1 :(得分:0)
试试这个,我已经通过在我的适配器类上解决了这个问题,
View view = null;
convertView = null; in the get view and comments the else part of
if (convertView == null) {
}
/*else{
} */