User Tools

Site Tools


android_learning:headfirst_android_development_notes:chapter_2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
android_learning:headfirst_android_development_notes:chapter_2 [2016/01/06 06:06] – [p. 43] mithatandroid_learning:headfirst_android_development_notes:chapter_2 [2016/01/07 04:45] (current) mithat
Line 1: Line 1:
-<WRAP center round important 60%> 
-Under development. 
-</WRAP> 
- 
 ====== Chapter 2 notes ====== ====== Chapter 2 notes ======
  
 ===== About XML ===== ===== 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 projectbut you do need basic XML knowledge.+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 projectbut 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: 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]]//Introduction// through //Attributes//.+  * W3School’s [[http://www.w3schools.com/xml/xml_whatis.asp|XML tutorial]] (look at //Introduction// through //Attributes//)
   * A reasonable tutorial (video) by Mark Lassof:\\    * A reasonable tutorial (video) by Mark Lassof:\\ 
 {{youtube>y6DmCUH-4MQ?600x360&rel=0}} {{youtube>y6DmCUH-4MQ?600x360&rel=0}}
 +\\
  
-It might help you to know that XML was originally developed for use with Web technologies. It has since been adopted for use in many different situations. It’s particularly popular in Java culture.+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 ===== ===== p. 42 =====
Line 31: Line 28:
 ===== p. 45: Some notes on Views ===== ===== 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.+**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.+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.+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.
  
 <WRAP center round tip 100%> <WRAP center round tip 100%>
-The first thing you should do when adding a new View to a layout is to change its name to something semantically useful!+//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 called ''button1'' or ''button7''.+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''.
 </WRAP> </WRAP>
    
-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 really bad practice, but Android Studio does it anyway.+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 ===== ===== p. 48: Code block =====
Line 107: Line 104:
 </code> </code>
  
-===== Codecheck 1 =====+===== p. 56: Codecheck 1 =====
 The app through p. 56. The app through p. 56.
  
 {{youtube>XQdeIjk9QiM?600x360&rel=0}} {{youtube>XQdeIjk9QiM?600x360&rel=0}}
 +\\
 +
 +===== p. 57: Code block =====
 +Code from p. 57 is reproduced here to make it easy for you to copy/paste it into your project:
 +<code java>
 +package com.hfad.beeradviser;
 +import android.os.Bundle;
 +import android.app.Activity;
 +public class FindBeerActivity extends Activity {
 +    @Override
 +    protected void onCreate(Bundle savedInstanceState) {
 +        super.onCreate(savedInstanceState);
 +        setContentView(R.layout.activity_find_beer);
 +    }
 +}
 +</code>
 +
 +===== p. 59 =====
 +<code java>TextView brands = (TextView)findViewById(R.id.brands);</code>
 +Why do you have to cast the reference returned by ''findViewById(R.id.brands)'' to a ''TextView''? It's because the [[http://developer.android.com/reference/android/view/View.html#findViewById(int)|findViewById() method]] returns values of type ''View''. This syntax is clumsy and error prone, but it's the way Android does it.
 +
 +===== pp. 60-62 =====
 +<code java>String beerType = String.valueOf(color.getSelectedItem());</code>
 +Why do you need to convert the value returned by ''Spinner.getSelectedValue()'' to a String? It's because that method returns a value of type ''Object''. See the [[http://developer.android.com/reference/android/widget/Spinner.html|Spinner documentation page]] and search for "getSelectedValue".
 +
 +===== p. 65: Codecheck 2 =====
 +The app through p. 65.
 +{{youtube>_pNMNfbp1Nw?600x360&rel=0}}
 +\\
 +
 +===== p. 66: Quicktip =====
 +Creating a new class in Android Studio
 +{{youtube>HNhzmUel8nU?600x360&rel=0}}
 +\\
 +
 +===== p. 66: Code block =====
 +Code from p. 66 is reproduced here to make it easy for you to copy/paste it into your project:
 +<code java>
 +package com.hfad.beeradviser;
 +        import java.util.ArrayList;
 +        import java.util.List;
 +
 +public class BeerExpert {
 +    List<String> getBrands(String color) {
 +        List<String> brands = new ArrayList<String>();
 +        if (color.equals("amber")) {
 +            brands.add("Jack Amber");
 +            brands.add("Red Moose");
 +        } else {
 +            brands.add("Jail Pale Ale");
 +            brands.add("Gout Stout");
 +        }
 +        return brands;
 +    }
 +}
 +</code>
 +
 +===== p. 69 =====
 +The [[http://developer.android.com/reference/java/lang/StringBuilder.html|StringBuilder]] class.
 +
 +===== p. 71: Finished =====
 +{{youtube>mkq6viA6uHw?600x360&rel=0}}
 +\\
  
  
android_learning/headfirst_android_development_notes/chapter_2.1452060382.txt.gz · Last modified: 2016/01/06 06:06 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki