Androidwear development of the HelloWorld chapter

Source: Internet
Author: User

Through the previous study, we have set up the environment, so that we can be really developed.

First, create the Wear project

With the Project Creation Wizard, you can create good one wear projects step-by-step:

1. Create a new project, fill in the application name, application package name, project location, and get familiar with Android.

2. Here we choose the Wear SDK

3. Create a wearactivity to activate the activity portal

4. With a good name, we can do it by default.

Second, correction error

Wait a moment as to help you set up the project, but you will find an error.

System can not find watchactivity, here I Google A, got the answer wear support library is not this watchactivity, only insetactivity.

So as long as we replace the watchactivity with insetactivity, then we will prompt you to ovveride the Onreadyforcontent method, and then cut the oncreate into here to run the

Third, edit the code

The code is as follows Myactivity.java

 PackageCom.example.bvin.androidwear_helloworld;ImportAndroid.os.Bundle;Importandroid.support.wearable.activity.InsetActivity;Importandroid.support.wearable.view.WatchViewStub;ImportAndroid.util.Log;ImportAndroid.widget.TextView; Public classMyActivityextendsinsetactivity {PrivateTextView Mtextview; Private StaticString TAG = "MyActivity"; @Override Public voidonreadyforcontent () {Setcontentview (r.layout.activity_my); FinalWatchviewstub stub =(watchviewstub) Findviewbyid (r.id.watch_view_stub); Stub.setonlayoutinflatedlistener (NewWatchviewstub.onlayoutinflatedlistener () {@Override Public voidonlayoutinflated (watchviewstub stub) {Mtextview=(TextView) Stub.findviewbyid (R.id.text); LOG.D (TAG,"TextView:" + mtextview.gettext () + "view=" +Mtextview);    }        }); } @Overrideprotected voidonCreate (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>

Notice here that there is a rectlayout a roundlayout, a circular table layout, a square table layout.

Iv. Creating the simulator

This is no problem, you can run the boot simulator directly, this simulator is very fun.

Create a round simulator

Start, boot a series of tutorials, this interface beautiful dead

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

Five, the operation

Well, the simulator is square?

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.