Honeypad Tutorial >

Honeypad Exercise 1

In this exercise, you will modify the Honeypad app with the following changes:

  • Make the app target Honeycomb devices.
  • Integrate the Action Bar into the App.
  • Create a new activity named NotepadActivity which will host Fragments.
  • Change the main activity to NotepadActivity in the manifest file.
[Exercise 1] [Exercise 2] [Exercise 3] [Exercise 4] [Exercise 5]

Step 1 : Import the Honeypad_Start Project into Eclipse

Import the Honeypad_Start project into Eclipse. To do this, create a new Android project in Eclipse, and then select Create project from existing source in the New Android Project dialog box

The Honeypad_Start project is the starting point of our tutorial and this is a modified version of Notepad tutorial.

  1. Right-Click the Honeypad_Start project in eclipse and click Properties. This brings up the Properties dialog box. Click Android in the left pane to bring up the Project build target list. Check that Android 3.0 ( or higher) is available as one of the targets. If it is not, please bring up the Android SDK and AVD Manager and follow the steps outlined at Installing Android sdk to install Android 3.0, API Level 11. Once the target Android 3.0 has been installed, change the Build Target to Android 3.0, API Level 11.
  2. Specify the android:minSdkVersion as 7 and android:targetSdkVersion as 11. Please note this tutorial will work for API Level 7 and above
         <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11"/>
  3. Define style ThemeHoneypad for API Level 7 and API Level 11.

    For SDK Level 7 add following style definition to the file res/values/styles.xml. We are extending Theme.Light

     <style name="ThemeHoneyPad" parent="android:Theme.Light"/>

    For SDK Level 11 add following style definition to the file res/values-v11/styles.xml. We are extending Theme.Holo.Light as this theme is only available for API Level 11 and above.

     <style name="ThemeHoneyPad" parent="android:Theme.Holo.Light"/> 
  4. Turn on the hardware acceleration by specifying android:hardwareAccelerated="true" in the AndroidManifest.xml file.
    <manifest android:hardwareAccelerated="true">
    </manifest >

This completes Step 1 of Exercise 1.

Step 2 : Create new Activity to host Fragments.

  1. Right-click on the src folder in Package Explorer and click on New --> class. In the 'New Java Class' window which comes up add the class name as NotepadActivity in the package com.example.android.honeypad . Add the super class as android.support.v4.app.FragmentActivity and click FINISH.
  2. Open layout file res--> layout--> notepad.xml, this will be the layout for this activity. It uses a container to host the fragments @+id/list.
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/list" android:layout_width="match_parent"
            android:layout_height="match_parent" /> 
  3. Override onCreate(..) method of NotepadActivity and set the notepad.xml as the content view.
    protected void onCreate(Bundle savedInstanceState) {

This completes Step 2 of Exercise 1.

Step 3 : Add Action Item to the Action Bar

In this step we will add an action item AddNote to the Options Menu in the Action Bar.

  1. Override onCreateOptionsMenu in NotepadActivity class. Populate it using the MenuInflater from R.menu.notepad_menu resource file defined in res/menu/notepad_menu.xml file.
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.notepad_menu, menu);
        return super.onCreateOptionsMenu(menu);

    Code below shows the contents of res/menu/notepad_menu.xml file

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:id="@+id/add_note" 
        android:showAsAction="ifRoom|withText"  />

This completes Step 3 of Exercise 1.


This completes Exercise 1. You can refer to the Honeypad_Checkpoint_1 project to check your solution or catch up. Please proceed to Exercise 2 as the next step.

↑ Go to top

← Back to Honeypad Tutorial