2013-02-18 42 views
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> 
+0

什么是'mInflater'什么是你的堆栈跟踪/异常? – 2013-02-18 17:57:05

+0

什么是mInflater?你也可以添加logcat日志吗? – lokoko 2013-02-18 17:57:18

+0

mInflater是在开始时定义的变量 'private LayoutInflater mInflater;' – 2013-02-18 18:14:29

回答

0

你应该利用这个膨胀的项目:

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

编辑:

parent是的ViewGroup中你的虚拟视图将被插入,在你的情况下,来自t的父参数他得到View()方法..

+0

这有多奇怪?昨天晚上它不工作,今天它正在工作。 Eclipse IDE有多糟糕:(已解决问题感谢所有人。 – 2013-02-19 07:53:20