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 trialJeffrey Kwok
3,006 PointsI'm having difficulty parsing a JSON file onto a listview for a personal project
Background: I'm trying to parse a JSON file into a listview. I've been following the "Building the Weather app" and "listview &adapter" tutorials and trying to apply those lessons into my project
Problem: I'm at the parcelable section of the tutorial and I'm having difficultly applying it into my project. My project is different from the weather app because it only has one list and no buttons. I'm having trouble passing information from my adapter to the MainActivity and I would appreciate any advice. Thank you
1 Answer
Seth Kroger
56,414 PointsYou only really need to make something Parcelable if you're passing it through an Intent or Bundle. Since you only have the one Activity so far, it's not really needed. Really all you need to do is store the resulting data a member variable in MainActivity and create the Adapter passing along the list of parsed data.
Jeffrey Kwok
3,006 PointsJeffrey Kwok
3,006 PointsHi Seth,
Thank you for the reply. So I will go ahead and declare member variables in MainActivity. I have already created an adapter class but how do I initialize the adapter in MainActivity?
Seth Kroger
56,414 PointsSeth Kroger
56,414 PointsThere really isn't any difference in initializing the adapter in MainActivity or another Activity. You construct a new one with the list and context and set the ListView's adatper to it. The difference is in how you come by the list data, not how you use it.