2013-09-03 3 views
0

나는 listview와 같은 gridview를 가지고 있습니다. 그것은 ...gridview가 두 번째로 작동하지 않았습니다.

로그 캣을 먼저 올바르게 실행 작동하지만 누를 때 뒤로 GRIDVIEW이 활동을 돌아, 약간의 오차가 얻을 : android.database.CursorWindowAllocationException을 : 2천48킬로바이트의 커서 창 할당에 실패했습니다. # 커서 열기 = 761 (이 proc = 761에 의해 열리는 커서 #)

나는 그 해결책을 항상 커서에 대한 것입니다. ... 난 .. 커서 때 채우기 항목 정보를 닫습니다하지만 일을 일부러

내 GRIDVIEW 코드 :

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; 

} 

답변

0

재정의 어댑터에서이 방법 클래스 및 또한 배열의 크기를 인쇄 할 수 있습니다 단지 하나의 vale을 가질 수 있습니다.

@Override 
public int getCount() { 
    return stock.size(); 
} 
1

이것은 닫힌 커서에 액세스하려고하기 때문입니다. 그래서이 줄

cursor.close(); 

을 제거하고 커서가 제대로

활동에서의 활동이나 조각에서이 줄을 쓰기 관리 조각에서

startManagingCursor(pass Your Cursor object here); 

getActivity().startManagingCursor(pass Your Cursor object here); 
관련 문제