User Tools

Site Tools


android_learning:headfirst_android_development_notes:chapter_12

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_12 [2016/04/24 03:50] – [p. 524: Code block] mithatandroid_learning:headfirst_android_development_notes:chapter_12 [2016/04/24 04:08] (current) – [p. 513-514: Code block] mithat
Line 1: Line 1:
 ====== Chapter 12 ====== ====== Chapter 12 ======
  
-This is just some text to get the section below to clear the Table of Contents. Otherwise the whole code block would appear very narrow. Kludgey for sure, but it gets the job done.  \\+This is just some text to get the section below to clear the Table of Contents. Otherwise the whole code block would appear very narrow. 
 + 
 +Kludgey for sure, but it gets the job done.  \\
  \\   \\ 
  \\   \\ 
Line 200: Line 202:
             // Get the name, description, and image for drinkNo:             // Get the name, description, and image for drinkNo:
             Cursor cursor = db.query ("DRINK",             Cursor cursor = db.query ("DRINK",
-                    new String[] { +                    new String[] 
-                        "NAME",  +                        {"NAME", "DESCRIPTION", "IMAGE_RESOURCE_ID", "FAVORITE"},
-                        "DESCRIPTION", +
-                        "IMAGE_RESOURCE_ID",  +
-                        "FAVORITE" +
-                    },+
                     "_id = ?",                     "_id = ?",
                     new String[] {Integer.toString(drinkNo)},                     new String[] {Integer.toString(drinkNo)},
Line 300: Line 298:
         setContentView(R.layout.activity_top_level);         setContentView(R.layout.activity_top_level);
  
-        AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {+        AdapterView.OnItemClickListener itemClickListener = 
 +            new AdapterView.OnItemClickListener() { 
             @Override             @Override
-            public void onItemClick(AdapterView<?> parent, View view, int position, long id) { +            public void onItemClick (AdapterView<?> parent, View view, 
-                if (position == 0) { +                int position, long id) { 
-                    Intent intent = new Intent(TopLevelActivity.this, DrinkCategoryActivity.class); +                    if (position == 0) { 
-                    startActivity(intent); +                        Intent intent = new Intent(TopLevelActivity.this,  
-                }+                            DrinkCategoryActivity.class); 
 +                        startActivity(intent); 
 +                    }
             }             }
         };         };
Line 317: Line 319:
         ListView listFavrotites = (ListView)findViewById(R.id.list_favorites);         ListView listFavrotites = (ListView)findViewById(R.id.list_favorites);
         try {         try {
-            SQLiteOpenHelper starbuzzDatabaseHelper = new StarbuzzDatabaseHelper(this);+            SQLiteOpenHelper starbuzzDatabaseHelper =  
 +                new StarbuzzDatabaseHelper(this);
             db = starbuzzDatabaseHelper.getReadableDatabase();             db = starbuzzDatabaseHelper.getReadableDatabase();
  
Line 327: Line 330:
  
             // Map data to list via adapter             // Map data to list via adapter
-            CursorAdapter favoriteAdapter = new SimpleCursorAdapter(TopLevelActivity.this,+            CursorAdapter favoriteAdapter = new SimpleCursorAdapter( 
 +                    TopLevelActivity.this,
                     android.R.layout.simple_list_item_1,                     android.R.layout.simple_list_item_1,
                     favoritesCursor,                     favoritesCursor,
Line 336: Line 340:
  
             // Handle click events on list items - show favorite item's activity             // Handle click events on list items - show favorite item's activity
-            listFavrotites.setOnItemClickListener(new AdapterView.OnItemClickListener() {+            listFavrotites.setOnItemClickListener( 
 +                new AdapterView.OnItemClickListener() {
                 @Override                 @Override
-                public void onItemClick(AdapterView<?> parent, View view, int position, long id) { +                public void onItemClick( 
-                    Intent intent = new Intent(TopLevelActivity.this, DrinkActivity.class); +                    AdapterView<?> parent, View view, int position, long id) { 
-                    intent.putExtra(DrinkActivity.EXTRA_DRINKNO, (int)id); +                        Intent intent =  
-                    startActivity(intent);+                            new Intent(TopLevelActivity.this, DrinkActivity.class); 
 +                        intent.putExtra(DrinkActivity.EXTRA_DRINKNO, (int)id); 
 +                        startActivity(intent); 
 +                    }
                 }                 }
-            });+            );
  
  
         } catch(SQLiteException e) {         } catch(SQLiteException e) {
-            Toast.makeText(TopLevelActivity.this, "Database unavailable", Toast.LENGTH_SHORT).show();+            Toast.makeText(TopLevelActivity.this, "Database unavailable", 
 +                Toast.LENGTH_SHORT).show();
         }         }
     }     }
Line 538: Line 547:
 </file> </file>
  
-===== Logcat =====+===== Debug with the system log =====
 This isn't covered until Chapter 13 in the book, but it's worth using here. This isn't covered until Chapter 13 in the book, but it's worth using here.
  
android_learning/headfirst_android_development_notes/chapter_12.1461469810.txt.gz · Last modified: 2016/04/24 03:50 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki