====== Chapter 2 notes ====== ===== About XML ===== In the previous chapter, we pretty much punted our way through the XML parts of a basic Android Project. We’ll use Android’s XML configuration files to a greater extent in this and subsequent chapters. You don’t need to be an XML expert to write the XML parts of an Android project, but you do need basic XML knowledge. If you are brand new to XML and want a crash course in it, here are some resources for you to look into: * W3School’s [[http://www.w3schools.com/xml/xml_whatis.asp|XML tutorial]] (look at //Introduction// through //Attributes//) * A reasonable tutorial (video) by Mark Lassof:\\ {{youtube>y6DmCUH-4MQ?600x360&rel=0}} \\ It might help you to know that XML was originally developed for use with Web technologies and was based on HTML syntax. It has since been adopted for use in many different situations and is particularly popular in Java circles. ===== p. 42 ===== When creating the Beer Adviser app, * Don’t forget to use **hfad.com** as the Company Domain. * Be sure to change the Activity Name to **FindBeerActivity**. * Make sure that the Layout name is **activity_find_beer**. If you mess anything up, close the project, open the folder where your Android Studio projects are, delete the project, and start again. ===== p. 43 ===== Remember that Android Studio now puts the "meat" of the layout code in ''content_{whatever}.xml'' rather than in ''activity_{whatever}.xml''. Therefore, the file you should edit is ''content_find_beer.xml''. Also remember that the current version of Android Studio doesn’t create ''@string'' resources for TextViews but uses string literals instead. ===== p. 45: Some notes on Views ===== **View**s are what Android calls the UI widgets that make up an Android user interface. All views inherit from a View superclass. Button and TextView are two examples of Views. You specify the initial properties for Views in a ''content_{whatever}.xml'' layout file. You can add Views to a layout using Android Studio’s GUI builder or by manually writing the XML code. If you add a View to the layout using Android Studio’s GUI builder, Android Studio will give each View a unique name with the **android:id** attribute (e.g., ''android:id="@+id/button7"''). The name that Android Studio generates will be syntactically valid, but semantically it will not tell you much. //The first thing you should do when adding a new View to a layout is to change its name to something semantically useful!// If you don’t, you (or your boss, coworker, or instructor) will experience tremendous agony as you try to remember whether the button you want to use is ''button1'' or ''button7''. Notice that the text attribute for the button you added using the GUI builder was given as a string literal (''android:text="New Button"''). That’s bad practice, but Android Studio does it anyway. ===== p. 48: Code block ===== Code from p. 48 is reproduced here to make it easy for you to copy/paste it into your project: