tags:

views:

83

answers:

1

How would you go about to bind a JSONArray to an adapter, the adapter will be used to bind data to a spinner.

Of course I could iterate over the strings in the JSONArray and add 'em to a String array, but that seems cumbersome.

A: 

Create your own adapter class, extending BaseAdapter, that adapts your JSON data according to whatever rules you feel are appropriate. The built-in adapter classes are not well-suited for JSON data.

CommonsWare
I have not looked at how the BaseAdapter is implemented, but would there be difference in extending baseadapter or parse the JSONArray to an array of strings?
Felix
Well, you don't wind up with multiple copies of your data (one in the JSONArray, one in your string array).
CommonsWare
Well that's of course true, I guess you have to think 'bout these things when you are developing for smaller devices. I just have to figure out what methods to override in the BaseAdapter class.
Felix
You'll see some custom adapters here: http://github.com/commonsguy/cwac-adapter http://github.com/commonsguy/cwac-sacklist http://github.com/commonsguy/cwac-merge -- These are more for modifying existing adapter data in a composite pattern, but they may still be useful examples.
CommonsWare