我有一个像列表视图一样的网格视图。它在第一次运行时正常工作,但是当按下并返回具有 gridView 的活动时,会出现一些错误......
logCat:android.database.CursorWindowAllocationException:2048 kb 的光标窗口分配失败。# Open Cursors=761 (# 此proc打开的游标=761)
我看这样的问题,解决方案总是关于光标。我关闭光标,填充项目信息时..但它没有工作......
我的网格视图代码:
private void refreshList(String sql)
{
gridArray = new ArrayList<Stock>();
final Cursor cursor = _SQLite.RawQueryTry(sql, null);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
if (cursor != null)
{
if (cursor.moveToFirst())
{
for (int i = 0; i < cursor.getCount(); i++)
{
String stockName = cursor.getString(cursor.getColumnIndex("STOK_ADI"));
String stockNo = cursor.getString(cursor.getColumnIndex("STOK_NO"));
String stockCode = cursor.getString(cursor.getColumnIndex("STOK_KODU"));
String stockEntity = cursor.getString(cursor.getColumnIndex("BIRIM"));
String stockKdvOranı = cursor.getString(cursor.getColumnIndex("KDV_ORANI"));
String stockRatio = TableUtils.getFieldValue("KATSAYI", "BIRIM", stockEntity, "STOKBIRI");
String stockAmount = cursor.getString(cursor.getColumnIndex("MIKTAR"));
gridArray.add(new Stock(stockName, stockNo, stockCode, stockKdvOranı, stockEntity, stockAmount, stockRatio, processNo));
cursor.moveToNext();
}
}
}
cursor.close();
gridAdapter = new AdapterStockGridListView(this, R.layout.stockgridlistitems, gridArray);
gridView.setAdapter(gridAdapter);
}
我的适配器类在这里:
public class AdapterStockGridListView extends ArrayAdapter<Stock>
{
Context context;
int id;
ArrayList<Stock> stock = new ArrayList<Stock>();
public AdapterStockGridListView(Context context, int id, ArrayList<Stock> stock)
{
super(context, id, stock);
this.id = id;
this.context = context;
this.stock = stock;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
RecordHolder holder = null;
if (row == null)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(id, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.stockName);
holder.txtStockNo = (TextView) row.findViewById(R.id.stockNo);
holder.txtStockCode = (TextView) row.findViewById(R.id.stockCode);
row.setTag(holder);
}
else
{
holder = (RecordHolder) row.getTag();
}
Stock item = stock.get(position);
holder.txtTitle.setText(item.getStockName());
holder.txtStockNo.setText(item.getStockNo());
holder.txtStockCode.setText(item.getStockCode());
return row;
}
}
static class RecordHolder
{
TextView txtTitle;
TextView txtStockNo;
TextView txtStockCode;
}