0

当语句convertView = mInflater.inflate(R.layout.listitem_course, null);在 BaseAdapter 的以下重写方法中执行时,应用程序将停止。我不知道为什么。

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Log.i(StudyManagerDataSource.LOG_TAG,
            "CourseListAdapter -> getView called!");
    if (convertView == null) {
        Log.i(StudyManagerDataSource.LOG_TAG,
                "CourseListAdapter -> Convet view is null called 1!");
        convertView = mInflater.inflate(R.layout.listitem_course, null);

        mViewHolder = new ViewHolder();

        mViewHolder.courseNameTextView = (TextView) convertView
                .findViewById(R.id.courseNameTextView);

        convertView.setTag(mViewHolder);

    } else {
        mViewHolder = (ViewHolder) convertView.getTag();
    }

    Course mCourse = mCourses.get(position);

    mViewHolder.courseNameTextView.setText(mCourse.getCourseName());

    Log.i(StudyManagerDataSource.LOG_TAG,
            "CourseListAdapter -> getView executed!");

    return convertView;
}

的代码listitem_course如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/courseNameTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp" />
</LinearLayout>
4

1 回答 1

0

您应该使用它来为您的项目充气:

mInflater.inflate(R.layout.listitem_course, parent, false);

编辑:

parent是您的膨胀视图将插入的 ViewGroup,在您的情况下,是 getView() 方法的父参数。

于 2013-02-18T18:01:01.027 回答