Common android controls-textview, editview, button, and menu

Source: Internet
Author: User
Example 1: A Computing Application Program , Enter two numbers, click the button to calculate the product of two numbers and return the result. Click the menu button on the right of the simulator to display a menu related to and exiting on the input interface.
Project running:


Development steps:
1. Create an android Project
2. Add edittext, textview, edittext, And button to the layout file in sequence (you must add them to the layout file according to the display sequence of the control on the interface)
3. Create a new layout file to display the calculation results. Add a linearlayout and a textview to the layout file (the default layout file contains a linearlayout by default, therefore, you do not need to manually add it. The new layout file is empty by default, so you need to manually add it)
4. Write the first activity
A) Let the activity inherit the android Activity
B) override the oncreate () method of the activity.
C) set the layout file of the activity.
D) obtain the control object based on the control ID.
E) set the value of the control, which references string. the value in XML. set in XML file (preferably string. XML values for internationalization); this can also be set in the layout file;
5. Create an activity, resultactivity
A) Let the activity inherit the android Activity
B) override the oncreate () method of the activity.
C) set the layout file of the activity.
D) obtain the control object based on the control ID.
6. Compile the button listener in the first activity.
A) obtain the values of two edittext controls.
B) Create an intent object
C) store the two values in the intent object.
D) Use the intent object to enable resultactivity.
E) bind the listener to the button.
7. Get the intent object in the second activity (resultactivity ).
A) obtain the value saved in the intent object and forcibly convert it to the int type.
B) Calculate the product of two values
C) set the Control Value
8. In the first activity, override the oncreateoptionsmenu () method. This method is used to add menu items in the menu. We add two menu items.
9. Rewrite the onoptionsitemselected () method in the first activity. This method is called when you click the menu item in the menu. Judge. Call the finish () method when you click exit.
The project source code has been uploaded to the attachment and can be downloaded as needed.

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.