我是Android開發的初學者。當我在此列表視圖中垂直滾動時,會發生此問題。開關按鈕自動改變狀態。我該如何解決這個問題?代碼如下所示:在列表視圖中滾動時切換按鈕更改狀態
public class TrainerSessionAdapterView extends BaseAdapter {
public TrainerSessionAdapterView(Context context) {
this.context = context;
inflater = LayoutInflater.from(this.context);
workoutList = new ArrayList<>();
newSessionList = new ArrayList<>();
type = context.getResources().getString(R.string.type);
other = context.getResources().getString(R.string.other);
objectID = context.getResources().getString(R.string.object_id);
}
@Override
public int getCount() {
if (workoutList.isEmpty()) {
return 0;
} else {
return workoutList.size();
}
}
@Override
public ParseObject getItem(int position) {
return workoutList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
removeSession = new ArrayList<String>();
trainerWorkoutList = (ArrayList<String>)user.get("trainer_workout_type");
if (convertView == null) {
convertView = inflater.inflate(R.layout.session_listview, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (!workoutList.isEmpty() && position < workoutList.size() && change) {
ParseObject workoutObject = workoutList.get(position);
if (!TextUtils.isEmpty(workoutObject.get(type).toString()));
holder.sessionTypeView.setText(workoutObject.get(type).toString());
if(trainerWorkoutList!=null && workoutObject.getObjectId()!=null){
if (trainerWorkoutList.contains(workoutObject.getObjectId())){
holder.sessionSwitch.setChecked(true);
}
}
else{
holder.sessionSwitch.setChecked(false);
}
}
return convertView;
}
}
請發帖時使用的代碼提供更多的細節。不允許將代碼註釋爲解決最小字符要求的解決方法。 –