Adding a Coffee - Switching to our 'Coffee Check In' Screen

First of all, have a quick look at the resource layout (content_home.xml) we will be referring to, and familiarise yourself with the properties of the different buttons, especially the onClick, as you will have to refer to these in the following steps.

We won't need to implement specific Event Listeners for this step, instead we will use the simpler 'direct binding' approach where we associate a method to be triggered when our button is pressed.

So, navigate to the onClick property of the 'Coffee Check In' button (as above) and enter add for the method name.

Next, open your Home.java activity and add the following method

    public void add(View v)
    {
    goToActivity(this,Add.class,null);
    }

You should run your app at this stage just to see if it behaves like it should.

You will, more than likely, get an error along the lines of

android.content.ActivityNotFoundException: Unable to find explicit activity class {ie.cm.models/ie.cm.activities.Add};

Can you work out why, and more importantly, how to fix it? (Hint : it involves the AndroidManifest.xml file and you can find the answer in the section on Intents already covered in the lectures).

But before we modify the AndroidManifest File, there's a few other additions to the project we need to make, i.e.

  • we need to add a new style so we can display our Add screen properly (as it's layout is not part of a template, like so
 <style name="AppTheme.ActionBar">
        <item name="windowActionBar">true</item>
        <item name="windowNoTitle">false</item>
    </style>

and

  • we need to modify our RatingBar so we get to see nice blue stars (and not grey ones!) so set the following property
    android:progressTint="@color/bannerBGColor"
  • Finally, add the following to your manifest file
 <activity
    android:name=".activities.Add"
    android:label="@string/addACoffeeLbl"
    android:theme="@style/AppTheme.ActionBar" >
</activity>

and run the app again to confirm everything is ok so far.

and when you click 'Coffee Check In' you should get

Next we'll start with implementing the menu.

results matching ""

    No results matching ""