Reputation: 71
I'm trying to show a ListView filled with a SimpleCursorAdapter. The SimpleCursorAdapter receives a Cursor filled with the execution of a rawQuery like:
SELECT DISTINCT s.cod AS _id, s.name AS name FROM supplier s
INNER JOIN product p ON p.supplier = s.cod
INNER JOIN productprice pp ON pp.product = p.cod
WHERE
pp.category = 'w'
ORDER BY s.name
When I execute this query directly in the base, it returns 40 rows in less than 0.1 sec (normal). The execution of the rawQuery in the repository is very fast too. The problem is when I do the myListView.setAdapter(simpleCursorAdapter);
. It takes more than 2 minutes! So i've changed the query to SELECT cod AS _id, name FROM supplier ORDER BY name
and the execution of the setAdapter
was pretty fast ("normal fast" hshs).
My questions: Exist a limit of JOIN's that I can do in a rawQuery to fill a listView? Am I doing something wrong? Should I use query() in the repository instead of rawQuery()?
Sorry about the english and thanks in advance.
Upvotes: 0
Views: 814
Reputation: 2237
The Cursor you provide to the SimpleCursorAdapter is a resultset from the database query. If the database query is fast, then the problem is located in the CursorAdapter. I have experienced that CursorAdapters have poor performance (both using SimpleCursorAdapter and custom adapters extending CursorAdapter or ResourceAdapter). I ended up pulling the data from the Cursor, put in in an array, and extend the ArrayAdapter, which gave me much better performance.
Upvotes: 3