Saturday, 17 August 2013

CursorAdapter bindView disorder

CursorAdapter bindView disorder

i'm trying to populate a ListView from a SQliteDatabase with Cursor and
Loader, but all items are displayed in total disorder
My CursorAdapter class
@Override
public void bindView(View view, Context context, Cursor c) {
ItemHolder holder = null;
try{
holder = (ItemHolder) view.getTag();
} catch (Exception e){
e.printStackTrace();
}
if(holder != null){
System.out.println("b "+holder.position);
}
}
@Override
public View newView(Context context, Cursor c, ViewGroup parent) {
LayoutInflater inflater =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View nView = inflater.inflate(layoutID, parent, false);
ItemHolder holder = new ItemHolder();
System.out.println("a "+c.getPosition());
holder.position = c.getPosition();
nView.setTag(holder);
return nView;
}
Logcat output after a single full scroll return (a is position in
newView() and b in bindView() )
a 0
b 0
a 1
b 1
a 2
b 2
b 0
instead of
a 0
b 0
a 1
b 1
a 2
b 2
a 3
b 3
A check of the cursor in the adapter return correct data
c.moveToFirst();
for(int i = 0; i < c.getCount(); i++){
System.out.println(i+" "+c.getString(c.getColumnIndex(COL_NAME)));
c.moveToNext();
}
I use the latest anroid.support.v4 library

No comments:

Post a Comment