Android simple way to create an activity _android

Source: Internet
Author: User
Tags response code

The examples in this article describe how Android simply creates an activity. Share to everyone for your reference, specific as follows:

1 Create an Android project

Fill in the project information

2 Create a new activity

Right-click on the left side of Eclipse (default) you want to join the activity package, for example, my package is com. Indroid.layout. Then select New->class, type the name of the class (note the first letter), and click on Superclass's Browse. Finally, the activity is entered in choose a type. And then you can just click OK.

3) Create an activity layout

Create a layout XML page in the Rec/layout folder new->others->android->android XML file

4 Register created activity to Androidmanifest.xml

Use Eclisps to visualize Add, double-click androidmanifest.xml Select Tag application->add->activity, enter the name of the class you just created.

can also be added by hand, add under </activity> tags

<activity android:name= ". The name of the new activity"
 android:label= "title of the New Activity" >
</activity>

The point to note here is that android:name= "." Here's a point that says this activity is under the com.INdroid.layout of the package I chose.

5 Add the OnCreate method to the new activity and bind the layout.

Regarding the activity the jump question, must add, the button binding Setonclicklistener must place after the new Onclicklistener object, otherwise cannot jump.

To this end, an activity that can be used is created, and the next step is to add UI elements and implement the page response code

As an example of adding a checkbox, the effect is to click on the main activity interface and jump to the Checkboxactivity interface.

1. Add a button to the main activity interface. Open main ... XML, using the "+" of the outline window, add a button and fill in the button's properties
2, in the Src/activitymain class, namely the main activity interface response class to implement the page jump code,
① Declare button variables and listeners Onclicklistener
② realizes the Onclicklistener listener's jump logic, that is, the ONCLIHCK function
③ binding listener Onclicklistener to button
3. Add a checkbox widget to the Checkboxactivity interface
4, add the rendering code to the Checkboxactivity interface

For more information on Android-related content readers can view the site: "The activity of Android programming skills Summary", "Android Communication method Summary", "Android debugging techniques and common problems solution summary", " Android Introduction and advanced tutorials, summary of Android Basic components usage, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

Related Article

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.