CS 491 Lecture 6 – ListView and Adapters
September 25, 2012 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
cs491 mobile, fall 2012, lectures.
Before class
A
Before our next class:
Here’s a brief outline of the video’s contents:
- A need for series data widgets
- Several: ListView, GridView, Spinner
- Create a String array
- TextToSpeech
- onItemClick to speak
- onLongItemClick to delete
- addHeaderView
- creating a TextView programmatically
B
Before our next class:
Here’s a brief outline of the video’s contents:
- Custom lists
- Make a model
- Make a layout
- Make an adapter
- Construct it
- Override getView
- Inflate from XML
In class
With your partner, code up a little image gallery viewer, following these guidelines:
- Grab this image collection. Hook up your device or startup your emulator. Go to the DDMS perspective in Eclipse. Under File Explorer, drag the unzipped image collection onto the SD card, perhaps in the Downloads directory.
- Create a custom adapter to show an image and its caption. The caption is derived from an image’s file name. Strip off the date prefix and the extension, and replace any underscores with spaces.
- Use a GridView to tile the photos. From a developer’s perspective, GridView is almost identical to a ListView. The primary difference is there’s nothing like ListActivity. You’ll have to make your Activity subclass with a layout containing a GridView.
- If you have time, when a user click’s on an item in the GridView, fire up an intent to view the image. Use Intent.setDataAndType to pass in the URI/path (try Uri.fromFile) to the image and the MIME type (“image/jpeg”).
- Programmatically listing the files is done slickly with the File class. Create a File for your image directory. Call listFiles to get an array of Files that are the directories contents.
- To read from the SD card, you’ll need to request permission.