Android development: the second day -- the first time the control was used

Source: Internet
Author: User

First, let's talk about how to create an activity:

/** Key points for creating an activity * 1. an activity is a class, which must inherit from activity * 2. the oncreate Method * 3 needs to be rewritten. every activity must be in androidmainifest. configure in XML file * 4. add necessary controls for the activity **/

 

Step 2 creates a button control and a textview control for the activity.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"               android:orientation="vertical"               android:layout_width="fill_parent"               android:layout_height="fill_parent">    <TextView        android:id="@+id/myTextView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"/>        <Button         android:id="@+id/myButton"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/></LinearLayout>

 

At the same time, modify the relative layout (relativelayout) of the created project to a relatively simple linear layout (linearlayout ).

In addition, there are five layout methods for Android:

Framelayout (Framework layout), linearlayout (linear layout), absolutelayout (absolute layout), relativelayout (relative layout), tablelayout (table layout)

Return to the Java code, in the oncreate () method:

@ Override public void oncreate (bundle savedinstancestate) {// call the oncreate () method super in the parent class. oncreate (savedinstancestate); // sets the layout file setcontentview (R. layout. activity_main); // the return value of the following function is view, and view is the parent class textview mytextview = (textview) findviewbyid (R. id. mytextview); button mybutton = (button) findviewbyid (R. id. mybutton); mytextview. settext ("first textview"); mybutton. settext ("first button ");}

 

 

Note:

import android.widget.Button;import android.widget.TextView;

 

OK, running effect:

Work hard every day. Come on!

Bytes ------------------------------------------------------------------------------------------

Author: PANG Hui

Source: http://www.cnblogs.com/pang123hui/

This article is based on the signature 2.5 mainland China license agreement. You are welcome to repost, interpret, or use it for commercial purposes. However, you must keep the signature Pang Hui (including the link) of this Article ).

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.