IT tutorials
 
Mobile
 

Android Application Development : The ApiDemos Application (part 2) - Adding Your Own Examples to ApiDemos

1/8/2013 5:20:02 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

The ApiDemos application is a handy sandbox for your own testing, and adding a new menu entry and Activity to it is quite easy. But remember that whenever you upgrade your API, all of your changes will be lost. Don’t add code to the ApiDemo that you might want to save after an upgrade. It really is just a sandbox for quick tests.

With that caveat in mind, this section shows you how to add a new menu and screen to the ApiDemos application. We’ll do that by adding a new ToastTest Activity with a matching toast_test layout. We’ll then hook them into the ApiDemos application by adding them to the AndroidManifest.xml file.

First, create a file named toast_test.xml in the res/layouts directory and add the following content to lay out the widgets:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="wrap_content "
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Guess my favorite color:" />
    <RadioGroup android:id="@+id/RadioGroup01"
        android:layout_below="@id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RadioButton android:id="@+id/redButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Red" />
        <RadioButton android:id="@+id/greenButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Green" />
        <RadioButton android:id="@+id/blueButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Blue" />
    </RadioGroup>
</RelativeLayout>

					  

This layout creates a RelativeLayout layout manager named RelativeLayout01, specifying up a TextView and a RadioGroup. The TextView presents the user with the text “Guess My Favorite Color” while the RadioGroup, named RadioGroup01, contains three RadioButton widgets: redButton, greenButton, and blueButton. They have the text “Red”, “Green”, and “Blue”, respectively.

Next, create the view/ToastTest.java file. It simply responds to clicks from the layout:

package com.example.android.apis.view;

//Need the following import to get access to the app resources, since this
//class is in a sub-package.
import com.example.android.apis.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

public class ToastTest  extends Activity{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toast_test);

        final RadioButton redButton = (RadioButton) findViewById(R.id.redButton);
        redButton.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Toast.makeText(ToastTest.this, "Ooooh, red", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

					  

Here are some of the highlights of the code:

Like toast in a toaster, this text pops up when activated. This technique can be quite handy for debug code.

Finally, add a new activity element to the AndroidManifest.xml file:

<activity android:name=".view.ToastTest" android:label="Views/ToastTest" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.SAMPLE_CODE" />
    </intent-filter>
</activity> 

This activity element should be added right after the TextSwitcher1 demo.

 
Others
 
- Android Application Development : The ApiDemos Application (part 1) - Application Setup in the Manifest File, Finding the Source to an Interesting Example
- iphone Programming : Adding Missing Features (part 3) - Changing the Display Name, Enabling Rotation
- iphone Programming : Adding Missing Features (part 2) - Adding a Launch Image
- iphone Programming : Adding Missing Features (part 1) - Adding an Icon
- iphone Programming : Using Sensors - Accessing the Proximity Sensor
- Mobile Web Apps : Templating - Twitter Integration with Templating
- Mobile Web Apps : Ajax - Fetching HTML, Ajaxifying Links
- IPad : Working with Contacts - Adding a New Contact Right on Your iPad
- Bluetooth on the iPad : Bluetooth Stereo, Disconnect or Forget a Bluetooth Device
- BlackBerry Bold 9700 and 9650 Series : Fixing Problems - Web Browser Running Slowly, Automatic Memory Cleaning to Keep Running Smoothly
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us