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 Build a Weather App (2015) Building the Weather UI Starting at the Center

Derek Derek
Derek Derek
8,744 Points

activity_main.xml vs content_main.xml

Hello,

I am using Android Studio 1.5, and differently from Ben, I have two layout files: activity_main.xml and content_main.xml. At first, I wasn't able to follow Ben because in activity_main.xml, I could not add texts to the preview window. I googled on why, and I realized that on new versions of Android Studio, the layout changes had to be done on the content_main.xml. The problem is though, I cannot see the changes I am making on content_main.xml on the emulator.. Why is that? Any help is greatly appreciated!

2 Answers

i have redone the weather app on Android Version 1.5 and there are several issues that you need to take note of.

  1. you have two layout files for an activity when you chose Blank Activity. Which are activity_main.xml and content_main.xml. Do all your UI editing on the content_main.xml. in the case that you dont want the toolbar and the floating action bar (fab) go to the activity_main.xml and remove the relevant block for the toolbar and for the fab.

  2. when you have removed the fab and the toolbar not that the MainActivity.java has errors. this is because the action bar and the fab is referenced in code, yo may comment or remove the fab and the toolbar when you are not using them.

  3. when you are using ButterKnife library not that you need to use the @Bind annotation insted of @InjectView

  4. on the OkHttp library, please note you have to include compile 'com.squareup.okio:okio:1.6.0' in your dependencies as this helps on your buffering etc,(thus as far as i know). I had some error before and did some research and recommendation was to add that dependency, and it worked for me.

  5. also note that on your drawable variable declaration, you might need to declare it as below just to get you going on the new update, remember the drawable folder is now for the vector drawables etc: Drawable drawable = getResources().getDrawable(current.getIconId()); mIconImageView.setImageDrawable(drawable);

As you upgrade through the Android Studio version, be sure to do the most basic apps first that you have done before just to get the practical grip if the changes before getting into a large project. i will recommend the weather app because it uses most basic and crucial principles for you to appreciate version upgrades.

Derrick Shepherd
Derrick Shepherd
4,861 Points

Hello Hyun Jae Cho,

If you're just starting the project, If you're still in the beginning module, An easy way to avoid the complexities of activity_main.xml and content_main.xml, You may want to consider starting the project over in Android Studio by first creating a new project and choosing the "No Activity" template instead of "Blank Template". But ONLY if you haven't gone through several modules, unless you don't mind starting over.