0
我在這裏有一個非常簡單的適配器。一個我想要列表中有很多空白的地方。比方說1000。適配器後面的數據集只有5個元素。當這個適配器被加載到一個列表視圖中時,一切看起來都不錯,直到你滾動屏幕。然後重複位置並從數據集中獲取數據。爲什麼? getCount()在重寫時是否需要始終返回實際在數據集中的大小?爲什麼getCount()大於適配器數據集重複位置
private abstract class BlankEntriesAdapter extends BaseAdapter {
private final List<String> rowList;
public BlankEntriesAdapter(List<String> rowList) {
this.rowList = rowList;
}
@Override
public int getCount() {
//force a few blank spaces
return 1000;
}
@Override
public String getItem(int position) {
if (position < rowList.size()) {
return rowList.get(position);
}
return null;
}
@Override
public long getItemId(int position) {
RowItem item = getItem(position);
if (item != null) {
return item.rowId;
}
return 0L;
}
@Override
public boolean isEnabled(int position) {
return position < rowList.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//ISSUE IS HERE. Position numbers start to repeat. Expect position to match what row was drawn to screen.
String stringItem = getItem(position);
/*Load string to view if not null. Code not shown.*/
}
}
問題實際上是兩倍一個在getItemId()中,第二個在getView()中。你的建議讓我朝着正確的方向前進。當位置大於內部List <>時,convertView從不被重置。腦子放屁在我的最後,我總是操縱這些東西相信它或不相信大聲笑。 – LEO