Images with SimpleCursorAdapter

Tap on an item to bring up a piece of Toast containing a bigger version of the photo.

Source code in Images.zip

  1. MainActivity.java
  2. Helper.java
  3. images/R.java creates the int variables R.drawable.sample_0, R.drawable.sample_1, etc.
  4. appcompat/R.java
  5. activity_main.xml. The RelativeLayout contains a ListView.
  6. image_list_item.xml contains a horizontal LinearLayout.
  7. values/dimens.xml
  8. sample_0.jpg (213 × 285 pixels)
  9. sample_1.jpg (285 × 213)
  10. sample_2.jpg (285 × 191)
  11. sample_3.jpg (285 × 213)
  12. sample_4.jpg (285 × 190)
  13. sample_5.jpg (191 × 285)
  14. sample_6.jpg (285 × 213)
  15. sample_7.jpg (213 × 285)
  16. sample_thumb_0.jpg (45 × 60).
  17. sample_thumb_1.jpg (60 × 45)
  18. sample_thumb_2.jpg (60 × 40)
  19. sample_thumb_3.jpg (60 × 45)
  20. sample_thumb_4.jpg (60 × 40)
  21. sample_thumb_5.jpg (40 × 60)
  22. sample_thumb_6.jpg (60 × 45)
  23. sample_thumb_7.jpg (45 × 60)
  24. AndroidManifest.xml
  25. build.gradle (Module: app)

Create the project

Add the 16 .jpg fles to the project

In the Macintosh Finder, control-click on each .jpg file and select Copy. In the Android Studio project view, select the folder app/res/drawable, control-click on it, and select Paste.

Create class Helper

In the Android Studio project view, select the folder app/java/edu.nyu.scps.gridview.
File → New… → Java Class
Create New Class
Name: Helper
Kind: Class
OK

In the new file Helper.java, click on the word Helper and pull down
Code → Implement Methods…
Select onCreate and onCreate and press OK. Pull down
Code → Generate… → Constructor
Select the constructor with only four arguments and press OK.

Create image_list_item.xml

In the Android Studio project view, select the folder app/res/layout and pull down
File → New → Layout resource file
New Resource File
File name: image_list_item
Root element: LinearLayout
OK

Things to try