HelloWorld for AndroidWear Development

Source: Internet
Author: User

Through the previous study, we have set up the environment, and now we can actually develop it.

1. Create a Wear Project

You can create a Wear project step by step through the Project Creation Wizard:

1. Create a project, enter the application name, application package name, and project location at a time, and be familiar with android.

2. Here we select Wear SDK

3. Create a WearActivity and start the Activity entry.

4. Set the name so that we can use it by default.

Ii. Correcting Errors

Wait a moment, as will help you build the project, but you will find an error.

The system could not find the WatchActivity. Here I google it. The answer is that wear support library does not have this WatchActivity, and only InsetActivity.

So as long as we replace WatchActivity with InsetActivity, We will prompt you to ovveride the onReadyForContent method, and then cut the onCreate content here to run it.

3. Edit code

The Code is as follows: MyActivity. java

package com.example.bvin.androidwear_helloworld;import android.os.Bundle;import android.support.wearable.activity.InsetActivity;import android.support.wearable.view.WatchViewStub;import android.util.Log;import android.widget.TextView;public class MyActivity  extends InsetActivity {    private TextView mTextView;    private static String TAG = "MyActivity";    @Override    public void onReadyForContent() {        setContentView(R.layout.activity_my);        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {            @Override            public void onLayoutInflated(WatchViewStub stub) {                mTextView = (TextView) stub.findViewById(R.id.text);                Log.d(TAG, "TextView: " + mTextView.getText() + " view=" + mTextView);            }        });    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    }}

Activity_my.xml

<?xml version="1.0" encoding="utf-8"?><android.support.wearable.view.WatchViewStub    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/watch_view_stub"    android:layout_width="match_parent"    android:layout_height="match_parent"    app:rectLayout="@layout/rect_activity_my"    app:roundLayout="@layout/round_activity_my"    tools:context=".MyActivity"    tools:deviceIds="wear"></android.support.wearable.view.WatchViewStub>

Note that there is a rectLayout, A roundLayout, a circular table layout, and a square table layout.

4. Create a simulator

In this way, you can directly run the startup simulator, which is quite fun.

Create a circular Simulator

Boot, boot a series of tutorials, this interface is beautiful

You can double-click to open this interface and click start to find your own program.

V. Running

Well, what is the simulator?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.