-1

I have a class that extends BaseAdaptor and overrides the getItemViewType(int position) function. When I swap the cursor or notify the data set change, the value being passed in for position is always 0. However if I put a debug point in getItemViewType and call getCount, the value returned is 4. Similarly, calling getItem(0), getItem(1), getItem(2) and getItem(3) from the same debug point all return valid results.

Any ideas why position doesn't iterate though [0,1,2,3]?

Olshansky
  • 5,904
  • 8
  • 32
  • 47
  • it's not going to call getViewType() multiple times, if your getViewTypeCount is 1. The purpose of getViewType() is if you have different layouts in your adapterViews. – NameSpace Nov 13 '14 at 23:16

2 Answers2

1

Probably because getTypeCount returns "1" - so there's no need to actually iterate through "position" - Android assumes all view types are the same.

You should probably Override that method:

public int getViewTypeCount() {
    return 1;
}

But first, be sure that you know what it does. It's only useful if you have different types of data, not different values. See this post:

getViewTypeCount and getItemViewType methods of ArrayAdapter

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
0

The issue here was that my ListView's height was too small, so only the first row was ever getting rendered because the others were not visible.

Olshansky
  • 5,904
  • 8
  • 32
  • 47