我为ListAdapter.getView(int, View, ViewGroup)
创建了以下覆盖:
@Override public View getView (int pos, View view, ViewGroup parent) {
ArrayList<Course> courses = this.courselist.getCourses();
// Return "no item"?
if (courses.get(pos).getState() == CourseState.Removed) return new View(this.getContext());
if (view == null) view = ((Activity)this.getContext()).getLayoutInflater().inflate(this.rsrc, parent, false);
Course course = courses.get(pos);
((TextView)view.findViewById(R.id.coursename)).setText(course.getName());
((Button)view.findViewById(R.id.btnRemoveCourse)).setTag(course.getId());
return view;
}
是否可以返回“无项目”之类的内容?返回空View
会产生一条灰色线条,其高度为1个像素,并返回null
个结果NullPointerException
。