I'm trying to make a new android project in which I collect my data from an online JSON file. If I look on the internet, I can see a lot of examples where they are storing the collected data in a MatrixCursor. Personally, I think it's much easier (and much shorter/faster) to store all the data in a list in a model class. Is there a good reason why they are not using Lists instead of MatrixCursor, or what are the differences between them ?
Asked
Active
Viewed 247 times
1
-
yes, you can use it with out-of-the-box SimpleCursorAdapter, for example see my answer here http://stackoverflow.com/a/19860624/2252830 on how to show some web service api in ACTV – pskink May 21 '15 at 07:20
-
You can store data from an online JSON file in an ArrayAdapter as well, or am I wrong ? – Nike Sprite May 21 '15 at 07:53
-
sure, but how would you make ACTV to work with ArrayAdapter? hehehe see this question asked 5 minutes ago: http://stackoverflow.com/questions/30367712/autocompletetextview-adapter-not-set – pskink May 21 '15 at 07:55
-
Who said that I want to use ACTV ? :p And you can also filter on a list if you want (it's maybe al little bit more work) – Nike Sprite May 21 '15 at 08:00
-
you didn't say what component you want to use, besides in most cases you need a custom ArrayAdapter if your data item is not one TextView, with SCA and MC in most cases you don't need any custom adapters – pskink May 21 '15 at 08:04
-
Post some links for the examples using MatrixCursor, and we can look at each of them and see if MatrixCursor provides any real advantage over a custom adapter. – kris larson May 21 '15 at 10:40
1 Answers
0
I also prefer to have model classes that can be created from JSON data along with a custom ListAdapter
for those classes.
However, there are components such as SearchView
that specifically require a CursorAdapter
i.e. for search suggestions. In those cases. it's easier to put the data into a cursor like a MatrixCursor
, pass that to a SimpleCursorAdapter
and be done with it.

kris larson
- 30,387
- 5
- 62
- 74
-
Last week, I made a project using the `SearchView` with a normal list. So the `SearchView` doesn't explicitly require a `CursorAdapter` – Nike Sprite May 21 '15 at 08:57
-
@NickSpriet, sure you can do it but you need a 1) setOnCloseListener 2) custom POJO do store data 3) custom background search Thread/AsyncTask 4) custom adapter, and with CursorAdapter you can do it directly as i did in the link i posted above, now what is much easier (and much shorter/faster)? – pskink May 21 '15 at 10:05
-
@pskink nope, I didn't need all that stuff. The `SearchView` has an `setOnQueryTextListener`. You can use `onQueryTextChange` to filter and update your list. – Nike Sprite May 21 '15 at 11:54
-
@NickSpriet of course i meant `setOnQueryTextListener` (bad copy/paste) , so you need: 1) setOnQueryTextListener , the rest is the same... – pskink May 21 '15 at 12:20