Java-Android learning (Day 4)

Source: Internet
Author: User

Java-Android learning (Day 4)

Add a new Activity

We have learned that an Activity is equivalent to an interface (of course, it is not strict but easy to understand ).

After an Android Application is created, it is created by default:

①. A Class that inherits the Activity (this Class implements the Oncreate method of the parent Class and setContentView (R. layout. activity_main ));

②. A default layout file (under the res-layout folder );

③ OneNode (Android Application List (AndroidManifest)There is a correspondingNode ).

However, Android generally requires more than one interface. How can I add a new interface?

Through the above analysis, we can probably know what preparations to prepare:

① Create a layout file (in the res-layout folder );

② Create a new Class to inherit the Activity (implement the Oncreate method and associate it with the XML layout file just created );

③ Add a new Activity node in AndroidManifest. xml to describe ① and ②

Specific Operation: Switch the AndroidManifest file to the Application view. In the Application Nodes column under the view, you can Add a new Activity. Alternatively, if you are skilled, you can directly go to AndroidManifest. in the XML view, add nodes to view your habits.

The same Id of the widget in the Android Interface

In the first day, we know that "gen: is the path for saving the code file automatically generated by the ADT plug-in, and R. java in it will save all resource IDs"

All resources are mapped to R. java.

We often do this when accessing the resource View:

SetContentView (R. layout. activity_login); or userid = (EditText) findViewById (R. id. userId );

All resources are found through the R. java file.

What if the controls in two different layout files have the same Id? Will there be any problems when using and operating these controls?

In fact:

If the control IDs in the same file are the same, eclipse will report an error. If it is not in the same layout file, findviewbyid () the id you are looking for is the setContentView (R. layout..

Although this is the case, it is best to distinguish between IDs. Clear and easy to maintain. Click here.

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.