User Tools

Site Tools


android_learning:headfirst_android_development_notes:chapter_6

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_6 [2016/01/31 21:06] – [pp. 241-243] mithatandroid_learning:headfirst_android_development_notes:chapter_6 [2016/01/31 21:20] (current) – [Chapter 6 notes] mithat
Line 2: Line 2:
  
 <WRAP center round tip 90%> <WRAP center round tip 90%>
-When creating Activities in Android Studio 1.5, if you specify an **Empty** rather than a **Blank** layout template, the code that is generated will be very similar to what HFAD apps base their code on. This should allow you to use the book's code without modification. However, it will remove template code for some newer Activity features.+When creating Activities in Android Studio 1.5, if you specify an **Empty** rather than a **Blank** layout template, you will get template code that is very similar to what HFAD bases all its code on. This should allow you to use the book's code without modification. However, it will remove template code for some newer Activity features.
  
 The notes that follow assume you are creating **Empty** Activities. The notes that follow assume you are creating **Empty** Activities.
Line 78: Line 78:
 ===== p. 239 ===== ===== p. 239 =====
 If you use Android Studio's assistance to specify ''@array/options'', it will by default place the values in ''arrays.xml'' instead of ''strings.xml'': If you use Android Studio's assistance to specify ''@array/options'', it will by default place the values in ''arrays.xml'' instead of ''strings.xml'':
-{{youtube>PkFn13kh9ZA?large&rel=0}}+{{youtube>PkFn13kh9ZA?large&rel=0}}\\
 You'll find it easier if you add the needed ''string-array'' to ''strings.xml'' manually. You'll find it easier if you add the needed ''string-array'' to ''strings.xml'' manually.
  
Line 119: Line 119:
 </file> </file>
  
-Once you wrap your head around this, you should be able to change the code the launch the Intent in the book---whose Activity is yet to be created.+Once you wrap your head around this, you should be able to change the code to launch the Intent in the book (whose Activity is yet to be created).
  
 ===== p. 249: Creating a ListActivity ===== ===== p. 249: Creating a ListActivity =====
  
-When you create a new Activity that will become the app's "category" ListActivity, you'll need to+When you create a new Activity that will become ListActivity, you'll need to
   * Change ''... extends Activity ...'' to ''... extends ListActivity...''   * Change ''... extends Activity ...'' to ''... extends ListActivity...''
-  * Remove the call to ''setContentView()'' in the ctor.+  * Remove the call to ''setContentView()'' in the constructor.
   * Delete the layout file(s) that were generated for this Activity.   * Delete the layout file(s) that were generated for this Activity.
  
-The last item is optional. ''ListActivities'' have default layouts build into them; however, you can override these.+The last item is optional. ''ListActivities'' has layouts build into it; however, you can override them.
  
 Be sure to add the ''@string/title_activity_drink_category'' resource, and make up a reasonable name for the value. Be sure to add the ''@string/title_activity_drink_category'' resource, and make up a reasonable name for the value.
Line 134: Line 134:
 ===== p. 250-252: Adapters ===== ===== p. 250-252: Adapters =====
  
-The Adapter is a software engineering design pattern. The behind an Adapter object is that it functions as "glue" between two different objects. The most common application is to translate between a client and a source of data (e.g., a database). You can read more about the Adapter design pattern [[https://sourcemaking.com/design_patterns/adapter|here]].+The Adapter is a software engineering design pattern. The essence of an Adapter object is that it functions as "glue" between two different objects. The most common application is to translate between a client and a source of data (e.g., a database). You can read more about the Adapter design pattern [[https://sourcemaking.com/design_patterns/adapter|here]].
  
 In the DrinkCategoryActivity, the client is the DrinkCategoryActivity itself and the source of data is the static array of Drinks defined in ''Drink.java''. In the DrinkCategoryActivity, the client is the DrinkCategoryActivity itself and the source of data is the static array of Drinks defined in ''Drink.java''.
  
-The way the source of data for this project might seem to be over-engineered. Why create a class to encapsulate different drinks and put them into an array in the the class definition? The answer to this will unfold later in the app (we'll need an array of objects rather than an array of e.g. strings). And in a future chapter, we'll see other benefits to defining a class to represent your data objects and data containers.+The source of data for the DrinkCategoryActivity might seem to be over-engineered. Why create a class to encapsulate different drinks and put them into an array in the the class definition? The answer to this will unfold later in the app (we'll need an array of objects rather than an array of e.g. strings). And in a future chapter, we'll see other benefits to defining a class to represent your data objects and data containers.
  
 In the meantime, here's a version of the ArrayAdapter code that adapts a simple string array for use with the ListView instead of the ''Drink.dinks'' array. In the meantime, here's a version of the ArrayAdapter code that adapts a simple string array for use with the ListView instead of the ''Drink.dinks'' array.
  
 <WRAP center round info 90%> <WRAP center round info 90%>
-ListActivities have a ListView built into them.+A ListActivity has a ListView built into it.
  
 To get a reference to a ListActivity's ListView, use the ListActivity's [[http://developer.android.com/reference/android/app/ListActivity.html#getListView()|getListView()]] method. To get a reference to a ListActivity's ListView, use the ListActivity's [[http://developer.android.com/reference/android/app/ListActivity.html#getListView()|getListView()]] method.
 </WRAP> </WRAP>
- 
  
 <file java DrinkCategoryActivity.java> <file java DrinkCategoryActivity.java>
Line 194: Line 193:
   - Browse for the method you want to override, select it, and click //OK//.   - Browse for the method you want to override, select it, and click //OK//.
  
-''DrinkActivity.class'' and ''DrinkActivity.EXTRA_DRINKNO'' aren't created until p. 263. Therefore, if you add the code on these pages to your project, Android Studio will show you lots of red anger and prevent you from building it.+''DrinkActivity.class'' and ''DrinkActivity.EXTRA_DRINKNO'' aren't created until p. 263. Therefore, if you add the code on pp. 257-258 to your project, Android Studio will show you lots of red anger and prevent you from building it.
  
-You may want to experiment with a handler that (again) just makes a Toast:+Instead, you may want to experiment with a handler that (again) just makes a Toast:
 <code java> <code java>
     // Show a Toast when an item is clicked     // Show a Toast when an item is clicked
Line 212: Line 211:
  
 ===== p. 263 ===== ===== p. 263 =====
-In the code here, you can see the advantage of creating a class to represent and contain your data. It makes accessing an object and all pertinent info and behavior related to the object much easier.+In the code here, you can see the advantage of creating a class to represent and contain your data. It makes accessing an object and all pertinent data related to the object much easier.
  
 ===== p. 268 ===== ===== p. 268 =====
  
-I would add to the first point ("Sort your ideas ...") that you should use a top-level/category/detail-edit structure only if it makes sense for your app.+I would add to the first point ("Sort your ideas ...") that you should use a top-level/category/detail-edit structure only if it makes sense for your app! It's a good paradigm, but it's by no means universal.
android_learning/headfirst_android_development_notes/chapter_6.1454274395.txt.gz · Last modified: 2016/01/31 21:06 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki