Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Android Lists and Adapters Displaying Lists of Data Updating the Main Layout

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,795 Points

content_hourly_forecast.xml vs activity_hourly_forecast.xml

When I create the HourlyForecastActivity class, Android Studio creates 2 separate xml layouts file: activity_hourly_forecast.xml and content_hourly_forecast.xml.

The question is which xml file should I use and what is the difference between the 3 layouts files?

1 Answer

Hi Tonnie. It seems that you selected "Basic Activity" instead of "Empty activity" when you created that new HourlyForecastActivity.

"Empty Activity" creates an empty screen and comes with a single XML file: an empty ConstraintLayout. (It has a TextView displaying "Hello world" when you create a project with it).

"Basic Activity", on the other hand, creates a screen with a Floating Action Button (FAB) and generates 2 XML files: (using the names of your own created files)

  • activity_hourly_forecast.xml
  • content_hourly_forecast.xml

The "activity" file (activity_hourly_forecast.xml) is the CoordinatorLayout with the FAB, acting as a container for the other XML layout (the "content" file, content_hourly_forecast.xml). You will see this tag in the layout: <include layout="@layout/content_hourly_forecast" />, which is where content_hourly_forecast.xml is inserted.

The "content" XML file is the one you'd want to use to create your Hourly Forecast layout, if you really want to go with the "Basic Activity" here. To be honest, I don't think you'd need a FAB in that activity in this project (if I remember clearly), so you'd be better off deleting these 3 files and creating an "Empty Activity" instead.

Hope that helps :)