Development environment: android4.1.1
Experiment function:
In the first Hello world! Displays good in the activity for the label, which has a button named next. Click the Next button to enter the second activity, with only 1 close buttons in the second interface. Of course, people on the internet will be relatively safe to implement the shutdown function is not very simple, because Android has a special exit key to return the key. So the Close button does not implement it for the time being.
My 1th activity is helloworldactivity, and the 2nd activity is nextactivity.
Experiment Description:
1. To jump from 1 activity to another activity, this needs to be done through intent. Of course we need to bind a button on the Next button to press the listener (these seem to be Java knowledge, but I have never studied Java, can only use where to learn again), once the button is heard to have a key pressed, then through the intent to the specified 2nd activity trigger, This completes the function of this experiment.
2. In engineering, each activity corresponds to an XML file, which controls the location and attributes of each control.
3. The asserts directory can hold any file, the Res directory can also store arbitrary files, and res files in the Gen directory under the R.java file automatically generated a global ID.
4. The controls in the Strings.xml in the Res directory are also the corresponding ID numbers for each control in the R.jar. Of course layout under the Main.xml file is the same.
5. Androidmanifest.xml is the configuration file for the entire application.
6. Android.jar is the source of all the Android classes that the program applies to.
7. View is the parent class for all the controls in Android.
8. Activity can be understood as a human-computer interface, or as a container for a control.
9. In eclipse, use the crtl+shift+c annotation to select the area, and also to deselect the area with Ctrl+shift+c, where the annotation is a double ramp//.
If you use/**/to annotate, you use ctrl+shift+/to annotate the selected area, and ctrl+shift+\ to deselect the selected area.
10. Use alt+/is to increase the function of the word function, such as the hint.
Ctrl+shift+o can automatically add package files that are detected in eclipse that need to be imported.
SetText cannot use resource references, resource references display text should be in XML.
Comments for XML cannot appear in the attribute value code and cannot appear in markup. and the annotation format is <!--annotation content-->
After the XML statement ends, you do not need to end the symbol, such as a semicolon.
Test results (run in simulator):
After starting the program:
The main part of the experiment Code and comments:
Copy Code code as follows:
Helloworldactivity.java:
Package Com.example.helloworld;
Import android.app.Activity;
Import android.content.Intent;
Import android.view.view;//Note the case of view
Import Android.view.View.OnClickListener;
Import Android.os.Bundle;
Import Android.widget.Button;
public class Helloworldactivity extends activity {
Private Button My_button = null;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_helloworld);
My_button = (Button) Findviewbyid (R.id.my_button);
My_button.settext ("Next");
My_button.setonclicklistener (New Mybuttonlistener ());
}
Class Mybuttonlistener implements onclicklistener{
public void OnClick (View v) {
TODO auto-generated Method Stub
Intent Intent = new Intent ();
Intent.setclass (Helloworldactivity.this, Nextactivity.class);
HelloworldActivity.this.startActivity (Intent);
}
}
/**
* If the following statements do not, then the system will run directly into this program, rather than advanced to the master menu
* Access to this program through the Select Application interface
* In order to facilitate debugging, here will not enter the main menu interface.
/* @Override
public boolean Oncreateoptionsmenu (Menu menu) {
Getmenuinflater (). Inflate (R.menu.activity_helloworld, menu);
return true;
}*/
}
Nextactivity.java:
Package Com.example.helloworld;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.Button;
public class Nextactivity extends activity{
Private Button my_button2 = null;
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_next);
My_button2 = (Button) Findviewbyid (R.id.my_button2);
My_button2.settext ("@string/close"); SetText cannot use resource references inside
Resource reference display text should be in XML
My_button2.settext ("close");
}
}
Activity_helloworld.xml:
Copy Code code as follows:
<!--android:text= "@string/wuwei"-->
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparentleft= "true"
Android:layout_alignparentright= "false"
Android:layout_alignparenttop= "true"
Android:layout_centerhorizontal= "true"
android:text= "@string/wuwei"
Tools:context= ". Helloworldactivity "/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/my_button"
Android:layout_centerhorizontal= "true"
Android:layout_centervertical= "true"
/>
</RelativeLayout>
Activity_next.xml:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<button
Android:id= "@+id/my_button2"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
/>
</LinearLayout>
Androidmanifest.xml:
Copy Code code as follows:
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.example.helloworld"
Android:versioncode= "1"
Android:versionname= "1.0" >
<uses-sdk
android:minsdkversion= "16"
Android:targetsdkversion= "/>"
<application
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme" >
<activity
Android:name= ". Helloworldactivity "
Android:label= "@string/hello_world" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name= ". Nextactivity "android:label=" @string/close ">
</activity>
</application>
</manifest>
Experiment Summary:
A general understanding of the main features and tasks of several directories under the Android development project, the Android development process is probably familiar to me, because I do not know the Java and XML syntax, so the future of learning progress may be slightly slower, fortunately, I mainly do not get this direction, It's just that the lab has this project and has to get it.
Author: tornadomeet