2015-12-30 32 views
2

列表視圖中我添加了一個頭,在過去的列表視圖 當向上或向下滾動拋出異常 這是一個自定義視圖列表解決:例外,在Android的

public MyFixedListView(Context context) { 
    super(context); 
} 

public MyFixedListView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public MyFixedListView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
} 

public MyFixedListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
    super(context, attrs, defStyleAttr, defStyleRes); 
} 


@Override 
protected void dispatchDraw(Canvas canvas) { 
    try { 
     super.dispatchDraw(canvas); 
    } catch (IndexOutOfBoundsException e) { 
     e.printStackTrace(); 
    } 

} 

但現在的Android 6.0 0.1(棉花糖),再次,這次演出是前者的錯誤: 在我的籌碼trase:

java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 : at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) 

添加標題:

private void Create_Header_Sjd_init() { 

    LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); 
    convertViewHeader = inflater.inflate(R.layout.row_idea_list , null); 
    convertViewHeader.setBackgroundColor(getResources().getColor(R.color.gray_light_light)); 

    listView.addHeaderView(convertViewHeader, null, false); 
} 
+0

是頁眉/頁腳靜態還是他們滾動? – Tasos

+0

他們也滾動@Tasos –

+0

檢查本教程,如果你發現任何可能有幫助 - https://www.youtube.com/watch?v=8wOO91oLo2s – Tasos

回答

0

resovle這個錯誤通過子代碼:

 listView.setFooterDividersEnabled(false); 
    listView.addFooterView(new View(this), null, false); 
0

IndexOutOfBoundsException異常,也許你可以檢查有關數據的列表或項目視圖代碼

+0

我, m使用無盡的列表,很難 –

0

如果您的列表尺寸ID爲零,則添加標題列表視圖已經設置這個..

listView.setAdapter(null); 
+0

評論這行代碼:addHeaderView()永遠不會拋出異常 –

+0

當你調用addHeaderView()時,請告訴我你在onScroll()調用它() – ADM

+0

我只調用addheader()一次和第一次加載 –