ListAdapter: Fill views async, outsource query

60 views Asked by At

I am using a GridView and a CursorAdapter. All items in GridView have different types, so that my database query has many subqueries and is very slow.

So I decide to use a simple query (select only the ids). All subqueries should be outsourced asynchronous in CursorAdapter like this (dummy code). And after the async database queries the GridView item is updated.

@Override
public void bindView(View view, Context context, Cursor cursor) {

    long id = cursor.getLong(cursor.getColumnIndex(Columns._ID));
    ViewLoader.queue(id, view);

}

private class ViewLoader {
  public queue(long id, View view) {

    Bitmap bitmap = ... // load bitmap from web by using id
    String title = ... // query title from database  by using id
    String subtitle = ... // query subtitle from database by using id

    TextView titleView = (TextView) view.findViewById(R.id.title);
    titleView.setText(title);
    ...

    // update GridView
}

What is the best approach?

1

There are 1 answers

7
EE66 On

I dont think that this is the best approach. All of the thread swithing between UI and back thread will make your work unprodutable. I had used a Cursor that queried over 4 tables with about 30-40 columns and it worked ok, i can even say pretty fast. My point is that i think that the issue is with your binding. Images can and should be loded async (i use Picasso, but a lot of libraries can do the trick). My guess is that u start with the query (try to limit it to 30 rows and then us pagination technique to load more) and work trough the binding and everything will workout perfectly. Ask freely if i didnt explain myself.