In this example and the following examples, we will take a step-by-step approach to discuss all aspects of Android program design, and demonstrate how to design and develop Android applications in an example;
This example describes the resource file design and code Association, and provides the image jump function;
1. Choose File> New> Android project. On the displayed page, enter the following items:
Project name: exampleone;
Select android2.0 for build target;
Application name: exampleone
Package name: COM. Example
Create activity: mainactivity:
Click Next-> finish to complete the project building process;
2. design a new resource file: The interface layout file for the resource file mentioned here, open res-> layout in eclipse-> package explorer, right-click it, in the pop-up menu, choose new-> Android XML file, select layout in the pop-up dialog box, enter second_layout.xml in file (note that the resource file name must be in lower case), and click Finish on this page, then, you can see the editing page of the resource layout XML file. In the black window, right-click and choose [add...] textview and buttonare added to the menu respectively (input directly in the box and add one at a time ).
3. activity on the build screen: Click Src-> COM in the Resource Tree on the left. for example, right-click and choose new> class. In the displayed dialog box, name: secondlayoutactivity. In the superclass column, enter or select android. app. activity. Click Finish to automatically generate the painting class code;
4. click "androidmanifest" in the Resource Tree on the left. XML and double-click it. In the view displayed on the right, select application. In the application nodes column, click [add...] button. In the displayed dialog box, select "Create a new element at the top level, in application ", click "OK" and select "Browse..." after "name *" on the right of the subsequent main screen...] button. In the displayed dialog box, enter secondlayoutactivity and click OK to add the corresponding resource and code.
5. modify the generated code in the secondlayoutactivity class and copy oncreate in mainactivity (you can also right-click the class and choose source-> override/implement methods... in the pop-up box, select oncreate () and click OK. layout. change main to R. layout. second_layout can be used to connect the resources of the secondlayoutactivity class to the runtime function.
6. link the code of two screens to achieve redirection;
Modify the main. xml resource file and add a button. The attributes are as follows (you can modify or directly change the main. xml file in the properties box under the role le ):
Text: go to next view
ID: @ + ID/gotonextview
Modify the mainactivity. Java class and add the following functions:
Private void find_and_modify_gotonextview (){
Button button = (button) findviewbyid (R. Id. gotonextview );
Button. setonclicklistener (gotonextview_listener );
}
Private button. onclicklistener gotonextview_listener = new button. onclicklistener (){
Public void onclick (view v ){
Intent intent = new intent ();
Intent. setclass (mainactivity. This, secondlayoutactivity. Class );
Startactivity (intent );
}
};
Modify the existing oncreate overload function and add the following in the last part:
Find_and_modify_gotonextview ();
Modify second_layout.xml to the following:
Textview ID: @ + ID/gobackhint
Textview text: click the button to go back.
Button ID: @ + ID/turnback
Button text: turn back...
After adjustment, add the following code to secondlayoutactivity:
Private void find_and_modify_turnbackbutton (){
Button button = (button) findviewbyid (R. Id. turnback );
Button. setonclicklistener (buttonturnback_listener );
}
Private button. onclicklistener buttonturnback_listener = new button. onclicklistener (){
Public void onclick (view v ){
Finish ();
}
};
Add the following code lines at the end of oncreate:
Find_and_modify_turnbackbutton ();
7. Run the test:
Right-click exampleone and choose run as-> Android Application to run the test and check the jump results on the two pages;
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/jackxinxu2100/archive/2010/01/26/5257186.aspx