Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

grouping an array of objects

I am calling Weather Underground for a weather app. I return a list of hourly weather data that has both the day and the weather details at the same level. My for loop currently pull each hour as it's own object, and converts it to a Java Array that I feed into my recyclerview to populate a Cardview. Right now it creates a new card for each hour, but I need to to create a card for each day and insert the hours into their respective cards. It return 36 objects that can make either 2 or 3 cardviews if split right.

This is my loop:

JSONObject jsonHour = data.getJSONObject(i);
        Hour hour = new Hour();
        Log.v(TAG, String.valueOf(jsonHour));
        String day = jsonHour.getJSONObject("FCTTIME").getString("weekday_name_unlang");
        hour.setTime(jsonHour.getJSONObject("FCTTIME").getString("civil"));
        hour.setDay(jsonHour.getJSONObject("FCTTIME").getString("weekday_name_unlang"));
        hour.setETemp(jsonHour.getJSONObject("temp").getString("english"));
        hour.setMTemp(jsonHour.getJSONObject("temp").getString("metric"));

Right now the hour object consists of a Day, Metric Temp, English Temp and an Icon String. I need it to be Key day, Value all hours in said day. What am I missing? Ben Jakuben I could really use your help here!