2013-05-17 25 views
0

問題是這樣的: arraylist中有49項,適配器停在項目3沒有任何錯誤通知。該應用程序不會崩潰,並且不顯示文本視圖。這裏是適配器:自定義適配器失敗,沒有錯誤

public class ExhibitorObjectAdapter extends ArrayAdapter<ExhibitorObject> { 

public ArrayList<ExhibitorObject> exhibitors; 
public Activity act; 
public TextView tvExhibitorName; 
public ImageView ivExhibitorLogo; 

public ExhibitorObjectAdapter(Activity a, int layoutResourceId, ArrayList<ExhibitorObject> ex) { 
    super(a, layoutResourceId,ex); 
    this.exhibitors = ex; 
    this.act = a; 

} 

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return exhibitors.size(); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    View v = convertView; 
    if (v == null) { 
     LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = inflater.inflate(R.layout.single_exhibitor, null);   
    } 

    ExhibitorObject ex = exhibitors.get(position); 

    if (ex != null) { 

     //System.out.println(ex.companyName); 
     tvExhibitorName = (TextView) v.findViewById(R.id.textViewListExhibitorName); 

     tvExhibitorName.setText(ex.companyName); 

    } 

    return v; 
} 

}

編輯:這裏是包含列表視圖的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" > 


<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="18sp" 
    android:background="#134882" 
    android:paddingBottom="15sp" 
    android:paddingTop="5sp" 
    android:paddingLeft="5sp" 
    android:textColor="#FFFFFF" 
    android:text="Exhibitors" /> 


<ListView android:id="@+id/listViewExhibitors" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent"/> 


</LinearLayout> 

我還有其他幾個是正是這樣一個適配器和他們的工作只是罰款。我浪費了整整一天的時間(這可能是一個愚蠢的問題),任何幫助將不勝感激。謝謝。

+0

請編輯您的問題,幷包含包含列表視圖的XML佈局。 – Simon

+0

添加了佈局。謝謝。 –

+0

在構造函數中初始化你的數組列表 –

回答

0

將tvExhibitorName保存在適配器的範圍內是不好的。在getView()中使其成爲本地的,或者讓自己承受各種泄漏。這可能是你問題的根源。

另外,很奇怪的是,您不會誇大父母下的新視圖。可能會使用充氣(佈局,父母,錯誤)將有所幫助。

+0

爲什麼?在使用之前,他總是覆蓋它。 – dmon

+0

視圖無法釋放 –

+0

我會這樣做。謝謝。 –

相關問題