我在 getView() (PlanAdapter 类)中添加了新的 CheckBox
public View getView(int position, View convertView, ViewGroup viewGroup) {
Plan entry = listPlan.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.walkRow, null, false);
}
LinearLayout d = (LinearLayout)convertView.findViewById(R.id.checkBoxPlace);
TextView distance = (TextView) convertView.findViewById(R.id.distance);
distance.setText(" " + entry.getexerciseNumber());
TextView time = (TextView) convertView.findViewById(R.id.time);
time.setText(" " + entry.getwholeTime());
CheckBox chckStart = new CheckBox(context);
chckStart = entry.getCheckBox();
chckStart.setFocusable(false);
d.addView(chckStart); //here i get force close
return convertView;
}
当我向下滚动时它看起来很好,但是当我返回并向上滚动时它会崩溃。
计划类中的getter,setter
public CheckBox getCheckBox(){
return checkBox;
}
public void setCheckBox(CheckBox checkBox){
this.checkBox = checkBox;
}
和我在主类中的复选框
for (byte i = 0; i < db.planView.size(); i++) {
chcBox = new CheckBox(this);
chcBox.setId(i);
checkboxList.add(chcBox);
listOfPlan.add(new Plan(db.planView.get(i).getText().toString(), db
.count(db.planView.get(i).getText().toString(),
getApplicationContext()), chcBox));
}
日志:http://wklej.to/RpBvr/html