丢弃ListAdapter中的项目

时间:2015-01-11 20:49:56

标签: java android listadapter

我为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

0 个答案:

没有答案