Question

I am newer to Android and apologize for sounding so. The code would add little value so in short, I have a listfragment that pulls JSON to form the views. I simply wish to add methods/code so that onListItemClick will display a detailed view of the the list item as well as other information.

Does the implementation require placing the separate list items into respective objects so the data can be pulled and organized post item click?

I know this seems fairly straightforward, but I have yet to find a decent source/tutorial on how to do this. Any insight would be welcomed.

Was it helpful?

Solution

EDIT: Example code for creating list of objects from JsonArray.

ArrayList<MyObject> myList = new ArrayList<MyObject>();

public void parseJsonObjectIntoStorage(JsonArray data) {
    for (int i = 0; i < data.size(); i++) {
        JsonObject jsonObject = data.get(i).getAsJsonObject();
        // Your class should have a constructor that accepts a JsonObject
        // and constructs your object with GSON
        MyObject obj = new MyObject(jsonObject);
        myList.add(obj);
    }
}

First, you will need to parse the JSON into objects, which can be put into a list to feed into your adapter. I recommend GSON for taking care of this.

Here's a great tutorial for using ListViews. It also describes ExpandableListViews, which if I understand your question, is what you are looking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top