On the [Android Developer site]
(accessed 20121212) there is sample code to illustrate basic use of the
GridView layout. Since layouts are the foundation of Android code,
they are useful for study at the outset of learning to write for the
gridview.html page seems to date from "09 Dec 2012 21:51", but the
code does not run on Eclipse (Juno 4.2, service release 1, build ID
20121004-1855; Android SDK 4.1.2) as written. Below are my notes on
changes necessary to make it run.
- The code provides the content for
res/layout/main.xml, but by default Eclipse now names this file
activity_main.xml. Choose one or the other and make sure it is referred to consistently throughout the code.
- The code provides a
HelloGridView.javaclass containing an
onCreate()method, but by default Eclipse now places the skeleton of that method in a class called
MainActivity.java, not mentioned Google's tutorial. I recommend placing the content of Google's
onCreate()method into the skeleton generated by Eclipse. If, instead, you choose to name your class
HelloGridView.javaand to delete
MainActivity.java, then you must remember to edit the
AndroidManifest.xmlfile accordingly; that is where the
<application ... <activity ... / > </application>entry names the class of the project's main activity.
- The code prescribes a
/res/drawabledirectory, but you will have to create that; Eclipse currently creates only
/drawable-ldpi, etc. directories in
- Eclipse will supply
importstatements for all recognized methods in importable classes if you press CTRL-SHIFT-O (or CMD-SHIFT-O on a Mac keyboard). But if
import android.R;is supplied as a result, you may find errors being raised on lines calling the automatically generated
Rclass. If so, delete or comment out the line
It's likely that the sample code on Google's site will be updated before long, but in the past month there seems to have been a gap between the posted code and what is needed to run (and be studied) on the current Eclipse installation.