Android App Development

Android Wear : Develop Your First App

This is a continuation from our previous blog The Wearable Computing Revolution Begins: Building Android Wear App where we discussed Android Wear. In this blog, we will discuss the code involved.

There are few things that we need to keep in mind before starting our project. Here they are:

  1. Make sure you are using the latest release of Android Studio.

 

2. Install latest Android  SDK Platform as well as Android Wear System Image as shown in the image below:

Your system is now ready to create your first Android Wear application.

Getting Started

Steps:

  1. We’ll now start our new project – Create New Project.
  2. Select the form factors – “Phone and Tablet” and “Wear” as shown below:
  3. Go to next and finish the template
  4. Add blank activity.
  5. Give the project name as “Wear Demo”.

 

Now let’s discuss about the following three files that will be required:

  1. MainActivity.java: It is the Java code that launches the app and we will be adding the code.
  1. activity_main.xml: It is the user interface file for the watches that use Rectangle screen.
  2. strings.xml: This is be used to store our string values in order to localize our app.

Creating our UI (User Interface)

Let’s start by creating UI for Square screen watch.

  1. Click on activity_main.xml and you will see the TextView.
  2. We can change the Text Value in string.xml file as “Hello AcadGild!”.
  3. Drag a small button widget and name it as “CLICK IT”.
  4. Drag it into center of the view.
  5. It will be displayed as shown in the picture below:

Code:

  1. Go to MainActivity.java and add the following code for:

Declare Button and TextView as follow:

Button btnClick;
TextView txtMessage;

Initialize Button and TextView as:

btnClick= (Button) findViewById(R.id.button);
txtMessage= (TextView) findViewById(R.id.textMessage);

2. Create Button’s onClick() and put the code for changing the TextView color when Button is clicked. Follow the code given below:

btnClick.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
                   txtMessage.setTextColor(Color.RED);
           }
       });

Note: Make sure that there are no errors in the code. It’s time now to run your app.

Test your app

1.  Click on the Run button to run your app as shown below:

2. Select the emulator as shown below:

3. Run your app and the output is as shown below:

Before clicking on Button:

 

After Clicking on Button:

As explained above we have now successfully created our own application. Hope this blog was informative enough and you are now ready to create your own application for Android Wear.

Keep visiting our website Acadgild for more updates on Android and other technologies. Click here to learn Android App Development.

Android Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Close
Close