我運行的軟件,但是當我使用ListView滾動,其顯示正常,但一段時間後,我收到此錯誤信息:android.database.CursorIndexOutOfBoundsException
我試圖顯示光標到ListView。
我的適配器類:
private class DBAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
private Cursor c;
private Context context;
我的構造
public DBAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
getView方法
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.match_item, null);
holder.tvHome = (TextView)convertView.findViewById(R.id.ll_home);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.tvHome.setText(c.getString(3)+"("+c.getString(6)+")");
c.moveToNext();
return convertView;
}
}
簡單看法持有人
public static class ViewHolder {
public TextView tvHome;
}
}
適配器初始化
Cursor cur = dh.getAll();
startManagingCursor(cur);
String[] from = new String[] { "home" };
int[] to = new int[] { R.id.ll_home};
// Now create an array adapter and set it to display using our row
DBAdapter matches = new DBAdapter(this,R.layout.match_item, cur, from, to);
setListAdapter(matches);
誰能幫我解決這個問題?我到處找,但我找不到任何解決方案
最好的問候, 尼科斯
你能告訴我們你在哪裏實例化這個適配器的代碼? – davogotland
@davogotland我編輯了我的第一篇文章。包含適配器實例化 – Nicos
我認爲getView中的c.moveToNext()看起來很腥。但我不確定..如果你刪除它會發生什麼? – davogotland