@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d("Tasks", "getView正在调用!position是" + position);
Task task = getItem(position);
View view;
ViewHolder viewHolder;
if(convertView == null) {
Log.d("Tasks", "convert view为空,加载布局");
view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
viewHolder = new ViewHolder();
viewHolder.cb = (CheckBox) view.findViewById(R.id.is_finished);
viewHolder.taskTitle = (TextView) view.findViewById(R.id.taskTitle);
Log.d("Tasks", "将要调用view.setTag()");
view.setTag(viewHolder);
} else {
Log.d("Tasks", "convertView非空,复用view");
view = convertView;
viewHolder = (ViewHolder) view.getTag();
}
// CheckBox cb = (CheckBox) view.findViewById(R.id.is_finished);
// TextView taskTitle = (TextView) view.findViewById(R.id.taskTitle);
viewHolder.cb.setChecked(task.getIsFinised());
viewHolder.taskTitle.setText(task.getTaskTitle());
return view;
}
class ViewHolder {
CheckBox cb;
TextView taskTitle;
}