2017-2018-2 20165309 Experiment Report of Java object-oriented programming experiment 1. Installation test for Android Studio 2.Activity Test 3.UI Test 4. Layout Test 5. Event Processing test Step 1. Complete Hello world and ask to modify the contents of the Res directory, and Hello World will display its own number. The student number of a classmate before and after his own study number
- Found it
activity_main.xml
- Click on the left side of the yellow box
Design
- Find here on the right, enter the content required by the experiment
- The results are as follows:
2. Create thirdactivity, display your own number in thirdactivity, modify the code to let mainactivity start thirdactivity
- New Thirdactivity
mainRight-click, New Activity PointGallery...
activity_third.xmlmodify information in, as text required
Enter MainActivity.java , add code
import android.content.Intent;
Intent intent = new Intent(this,ThirdActivity.class);startActivity(intent);
Effect
3. Modify the code to let the toast message display its own learning number information
MainActivity.javaAdding code in
import android.widget.Toast;
Toast toast = Toast.makeText(MainActivity.this, "这是20165309吴思佳!", Toast.LENGTH_LONG);toast.show();
Screenshots in time, as follows:
4. Modify the layout
- The following can be done easily with the following
activity_main.xml Design layout:
5. Event handling: Build the project, run the textbook related code
Mainactivity.java
Package Com.wsj.helloworld;import android.app.activity;import Android.graphics.color;import Android.os.bundle;import Android.view.menu;import Android.view.view;public class Mainactivity extends Activity {int Co unter = 0; int[] Colors = {color.black, Color.Blue, Color.cyan, Color.dkgray, Color.gray, Color.green, Color.ltgray, Color.magenta, Color.Red, Color.White, color.yellow}; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the action Bar if it//is present. Getmenuinflater (). Inflate (R.menu.menu_main, menu); return true; public void ChangeColor (view view) {if (counter = = colors.length) {counter = 0; } view.setbackgroundcolor (colors[counter++]); }}
Activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><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" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/activity_ Vertical_margin "tools:context=". Mainactivity "> <analogclock android:layout_width=" wrap_content "android:layout_height=" wrap_content "Android:layout_alignparenttop=" true "android:layout_centerhorizontal=" true "Android:layout_marginto p= "90DP" android:id= "@+id/analogclock1" android:onclick= "ChangeColor"/> <ratingbar android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_margintop= "400DP" and Roidlayout_marginleft= "40DP"/></relativelayout>
- The results of the operation are as follows:
Iii. problems encountered in the experiment and their solutions
- Issue 1: Console error running App:default activitynot found hint
- Resolution 1: Because Androidstudio is in the process of creating the project, the default setting Lunche the project requires activity, because a simple widget program, if not associated with the application, does not need to create mainactivity in the Android project, After you Build project, you will get an error when debugging the installation.
- Open configuration,
appEdit Configurations...
launchOptions drop-down selectionNothing
- Issue 2: Error element selector must be declared
- Resolution 2: This is due to
.xml the wrong place, you have to move back to the corresponding folder.
- Issue 3: Error The user data image is used by another emulator. Aborting
- Resolution 3: This is because the emulator is not shut down properly, it should be turned off in the process, and then restarted.
- Issue 4: Error cannot resolve symbol
- Resolution 4: Click on the menu
File , Invalidate Caches / Restart then click on the dialog box Invalidate and Restart , clear cache and restart.
- Several ways to display messages on Android toast
Iv. Harvest of Experiments
According to the teacher's guidance blog and e-book, I completed the experiment, I feel very magical, when I can do their own development of Android is better:) ~
| Steps |
Time Consuming |
percentage |
| Demand analysis |
10min |
10 |
| Design |
20min |
20 |
| Code implementation |
20min |
20 |
| Test |
30min |
30 |
| Analysis Summary |
20min |
20 |
20165309 Experiment four Android programming