2013-02-18 41 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