0
我想要填充從遊標和裝載機一個SQLiteDatabase一個ListView,但所有的項目都經過單個完整CursorAdapter的bindView障礙
我CursorAdapter類
@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的輸出顯示在總混亂滾動返回(一個是在bindView在NewView的()的位置和b())
a 0
b 0
a 1
b 1
a 2
b 2
b 0
代替
a 0
b 0
a 1
b 1
a 2
b 2
a 3
b 3
光標在適配器回報的檢查正確性
c.moveToFirst();
for(int i = 0; i < c.getCount(); i++){
System.out.println(i+" "+c.getString(c.getColumnIndex(COL_NAME)));
c.moveToNext();
}
我用的是最新的anroid.support.v4庫