0
當語句convertView = mInflater.inflate(R.layout.listitem_course, null);
在BaseAdapter的以下重寫方法中執行時,應用程序停止。我不知道爲什麼。以下代碼中的LayoutInflator.Inflate方法有什麼問題?
@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>
什麼是'mInflater'什麼是你的堆棧跟蹤/異常? – 2013-02-18 17:57:05
什麼是mInflater?你也可以添加logcat日誌嗎? – lokoko 2013-02-18 17:57:18
mInflater是在開始時定義的變量 'private LayoutInflater mInflater;' – 2013-02-18 18:14:29