I have a JSON file that I want to parse. For each entry in the JSON file, I want to display an ImageButton (this will be an icon) and a TextView (a title). I’m just wondering what the best way of doing this is..
I DO NOT want to make a listview.. it is more of a grid view. I want 2-3 icons per row (so 2-3 columns) kind of like apple’s bookshelf
I’ve started off with..
json = JSONfunctions.getJSONfromSDCard("/sdcard link to the file") //this gets the json file
JSONArray entries = json.getJSONArray("entries");
ArrayList<String> alTitle = new ArrayList<String>();
for(int i=0;i<entries.length();i++){
JSONObject e = entries.getJSONObject(i);
..//create arraylist to store entries?
//alTitle.add(e.getString("title"));
}
//create ImageButton and TextView?
You can use a listview inside this activity or a ListActivity. Then use a list adapter to create a layout for each list item.
There are samples supplied in the SDK for this to get you started. You will find these in the android-sdk folder wherever you have installed this on your PC.
There are also many tutorials on the internet so I cannont list them all, but here are a few to get you started. These are the top google searches.
Android Series: Custom ListView items and adapters
Android: Dealing with ListActivities, customized ListAdapters and custom-designed items
UPDATE
Sorry I missed the specification of using a GridView. The officaial GridView documentation includes a full sample The same idea applies using an adapter you can compare the different type of view in the Hello Views section of the official documentation
Here is a full example, you will need to add any additional controll into your adapter. Again, there are samples in the sdk itself and these are invaluable to Android developers.