Creating an Activity

Step 2 dictates that you create an activity, which is also a simple process. Assuming that the layout file in step 1 is available at \res\layout\main.xml, you can use that file through its resource ID to populate the activity's view (see Listing 5-7).

Listing 5-7. Menu Test Harness Activity Class public class SampleMenusActivity extends Activity {

//Initialize this in onCreateOptions Menu myMenu = null;

^Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(R.layout.main);

For brevity, we have not included the import statements. In Eclipse, you can automatically populate the import statements by pulling up the context menu in the editor and selecting Source > Organize Imports.

0 0

Post a comment