2011-05-01 61 views
1

圖片我在DB的圖像,我把它放到我的GridView的這段代碼:GridView控件與數據庫

public void setNotes() 
    { 
     String[] columns = {NotesDbAdapt.KEY_ID, NotesDbAdapt.KEY_IMG, NotesDbAdapt.KEY_NAME, NotesDbAdapt.KEY_DATE, NotesDbAdapt.KEY_TIME}; 
     String table = NotesDbAdapt.NOTES_TABLE; 

     Cursor c = MainNote.mDB.getHandle().query(table, columns, null, null, null, null, null); 

     startManagingCursor(c); 

     SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
       R.layout.file_dialog_row, 
       c, 
       new String[] {NotesDbAdapt.KEY_IMG, NotesDbAdapt.KEY_NAME, NotesDbAdapt.KEY_DATE, NotesDbAdapt.KEY_TIME}, 
       new int[] {R.id.img, R.id.txt, R.id.date, R.id.time}); 

     adapter.setViewBinder(new NotesBinder()); 

     gridview.setAdapter(adapter); 
} 

一切ok,但卻滾動很慢,生澀。似乎每次都從DB獲取信息。如何解決它?

回答

1

此方法在API級別11中已棄用。請改用LoaderManager中的新CursorLoader類。它可以在後臺線程上執行遊標查詢,以便它不會阻塞應用程序的用戶界面。