Step 03 - Donate Button

    Rename the button in the Outline view:

    Step 03 - 图2

    Fix the lint error - and give the button the text ‘Donate!’. If all goes as expected, your xml files should be like this:

    1. <resources>
    2. <string name="action_settings">Settings</string>
    3. <string name="donateSubtitle">Please give generously</string>
    4. <string name="donateButton">Donate</string>

    If there is a deviation from the above - retrace your steps (delete the button) until you can match the above.

    We can now switch our attention to the Java Activity class Donate:

    Insert the following new field into the class:

    The class will have to be imported. The class name will always match the name in the Pallette:

    We are free to call the variable anything we like. However, in order to keep confusion to a minimum, always call the variable by the same name you used in the Outline view:

    Step 03 - 图4

    In onCreate - we need to initialise this variable:

    1. Log.v("Donate", "got the donate button");

    This is the complete activity class:

    Finding the log message can be very difficult, unless you set a filter. In the ‘LogCat’ view in eclipse, create a filter like this:

    If you then select the filter, we should see our message:

    Step 03 - 图6

    We should check the donate button actually exists before logging our success:

    1. if (donateButton != null)
    2. {
    3. Log.v("Donate", "Really got the donate button");