Divers
Divers

Reputation: 9569

GridView with images from DataBase

I have images in my DB and I put it to my GridView by this code:

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);
}

All ok, but but the scrolling is slow, jerky. Seems that information takes from DB every time. How to fix it?

Upvotes: 1

Views: 1381

Answers (1)

vettijack
vettijack

Reputation: 15

This method was deprecated in API level 11. Use the new CursorLoader class with LoaderManager instead. It can perform the cursor query on a background thread so that it does not block the application's UI.

Upvotes: 1

Related Questions