Step 04 - Documentation

The android documentation is particularly helpful and well designed. These are the two key starting points:

The first is designed to be read though as a guide, perhaps independent of any work in eclipse. You should get into the habit of devoting an hour or two a week just reading this section.

The Reference guide should always be open as you are working on labs or projects, and you should make a serious effort to get to grips with at least some of the information here.

Taking the Button class we have just started using. We can immediately find the reference just by knowing the import statement in our Activity class:

  1. import android.widget.Button;

.. translates to

(note the last three segments match the package name). Open this page now. Read just as far as the “Button Style” heading. There seems to be two ways of learning when an button event occurs. The first method is using the event handler/listener - but a second easier method is also available.

Try this now. Bring in a new method into Donate class:

  1. public void donateButtonPressed (View view)
  2. {
  3. Log.v("Donate", "Donate Pressed!");
  4. }

Then, edit the activity_donate xml file - and add a new attribute into the Button xml fragment:

  1. <Button
  2. android:id="@+id/donateButton"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:layout_alignParentBottom="true"
  6. android:layout_centerHorizontal="true"
  7. android:text="@string/donateButton"
  8. android:onClick="donateButtonPressed"/>

(the very last entry)

Save everything and execute the app, and monitor the log as you press the button:

Step 04 - 图1

We now have our first interaction working!