2017-2018-2 20165318 Experimental Report of Android program design--the cover of experimental report
Course : Java Programming Class : 1653 class name : Sun Xiaolin No. : 20165318
Instructor: Lou Jia Peng experiment Date : May 14, 2018
Experiment Time : 13:45-3:25 Experiment serial number : Experiment Four
Experiment name : Android programming
Experimental Requirements :
- Students who do not have a Linux base are advised to start with the Linux basics (new version) Vim Editor course
- Complete the experiment, write the experiment Report, the experiment report is published in the blog Garden, note that the experimental report is focused on the running results, the problems encountered (tool search, installation, use, program editing, debugging, running, etc.), solutions (empty methods such as "Check Network", "Ask classmates", "reading" 0 points) as well as analysis (what can be learned from it, what gains, lessons, etc.). The report can refer to the guidance of Fan Fei Dragon Teacher
- Plagiarism is strictly forbidden, and the results of the experiment of the perpetrator are zero, and other punitive measures are added.
Second, the contents and steps of the experiment
Directory
- The 24th chapter: the first knowledge of Android
- Task one: Installation test for Android Stuidio
- 25th Chapter: Activities
- Task Two: Activity testing
- 26th Chapter: UI Components
- 27th Chapter: Layout
- 28th Chapter: Listener
- Task five: Event processing test
- The problems encountered in the course of experiment and the solving methods
- Experience and summary of experiment
- Code Hosting
- PSP Requirements Analysis
- Resources
The 24th chapter: the first knowledge of Android
Build: This directory contains auto-generated files that include compilation settings, r classes, etc.
Libs: This directory contains the library files needed to develop Android apps
src: This directory holds the application's source code. java files. By default, it contains the Mainactivity.java file, and the source code J is part of the function you need to launch the app when you click on the app icon.
res: This directory holds all the resource files
drawable: This directory holds the Drawable object and some picture resources for the project
layout: This directory contains layouts files for each interface.
Menu: This directory holds the menus objects that are designed in the app
mipmap: This directory holds the application's main picture resources
values: This directory holds a collection of resources defined by strings, colors, and so on
androidmanifest.xml: This file is a file that describes the underlying characteristics of the application and defines each component.
Directory tree for Android Studio projects
Back to Catalog
Task one Android stuidio installation test:
Task requirements
- Refer to Android Development Easy tutorial, install Android Stuidio.
- To complete Hello world, ask to modify the contents of the Res directory, Hello world to display their own school number, the number of students before and after the student's school number.
- Learn the Android Stuidio debug app.
Experimental process
- Change the layout file to
activity_main.xml
text
android:text="Hello World!"
android:text="Hello World! 20165318 20165317 20165319"
You can also change the activity_main.xml
design
contents of the text view
layout file toHello World! 20165318 20165317 20165319
Learn Android Stuidio Debug app
The debugging process is as follows: Tools
Android
Android Device Monitor
Run results
Back to Catalog
25th Chapter: Activities
The four components of Android
- Activity
- Service
- ContentProvider
- Broadcast Receiver
Activity is one of the most commonly used and most common components of the Android system.
An application typically contains multiple activity
The activity class defines the following callback events
onCreate()
: This is the first callback method. It is called when activity is first created
onStart
: This method is recalled when activity becomes visible to the user
onResume()
: This method is called when the user starts interacting with the app
onPause()
: When the current activity is paused and the previous activity is recovering, the suspended activity will no longer receive input from the user or execute any code and calls
onStop()
: This callback method is called when activity is no longer a visual state
onDestroy()
: This method is called before the activity is destroyed by the system
onRestart()
: The callback method is called when the activity is restarted after it has been stopped
Back to Catalog
Task Two: Activity testing
Task requirements
- Build the project, run the textbook related code
- Create thirdactivity, display your own number in thirdactivity, modify the code to let mainactivity start thirdactivity
Experimental process
- Configure activity
- In file Androidmanifest.xml, you can configure activity as long as you add activity child elements to the application element
- In this task, we need to call thirdactivity, so add another activity in the Androidmanifest.xml
- Start and close activity
- Each control file activity requires a corresponding startup program file (. java) and the corresponding layout file (. xml)
- In this task, ask Mainactivity to start thirdactivity, so you need to modify the Mainactivity
MainActivity代码
Package Cn.edu.besti.is.sxx.activitydemo;import Android.os.bundle;import Android.app.activity;import Android.content.intent;import Android.view.menu;import Android.view.motionevent;import Android.view.View;import Android.view.view.ontouchlistener;import Android.widget.textview;import Android.widget.button;import Android.widget.toast;import Android.graphics.color;import Android.widget.analogclock;public class MainActivity Extends Activity implements Ontouchlistener {@Override protected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); TextView TV = (TextView) Findviewbyid (R.ID.TEXTVIEW1); Tv.setontouchlistener (this); } @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; } @Override public boolean onTouch (View arG0, Motionevent event) {Intent Intent = new Intent (this, thirdactivity.class); Intent.putextra ("message", "20165318 Sun Xiaolin"); StartActivity (Intent); return true; }}
Run
Back to Catalog
26th Chapter: UI Components
- Android provides a number of UI components that you can build on-demand user interface for your app
TextView
: A text label that is used to display text
EditText
: text box, a subclass of pre-defined TextView, with rich text editing capabilities
AutoCompleteTextView
: Auto-complete text label, similar to EditText. When the user enters the time will automatically give some complete suggestions
Button
: button, can press, click, by the user to complete an action
ImageButton
: Picture button, as the name implies
CheckBox
: A check box that can be used as a switch for users. This control is recommended when you have a series of options to choose from
ToggleButton
: Switch button with a "bulb" effect
RadioButton
: Radio button, only checked and unchecked
RadioGroup
: Is a collection of RadioButton, only one radio button can be selected within the same group
Spinner
: A drop-down list that allows the user to select one of several options
TimePicker
: Time picker allows users to enter time with 12-hour and 24-hour modes
DatePicker
: Date selector allows the user to enter a date
ProgressBar
: A progress bar that provides the user with the progress of a work, such as what is being done in the background
Back to Catalog
Task three: UI testing
Task requirements
- Build the project, run the textbook related code
- Modify the code to let the toast message display its own learning number information
Mainactivity.java
Package Cn.edu.besti.is.sxx.basiccomponents;import Android.content.context;import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.app.activity;import Android.util.attributeset;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.widget.button;import Android.widget.toast;public class Mainactivity extends Appcompatactivity {@Override PR otected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Button btnshow1= (button) Findviewbyid (R.ID.BTN1); Btnshow1.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View V {Toast toast = Toast.maketext (Mainactivity.this, "20165318 Sun Xiaolin", Toast.length_long); Toast.show (); } }); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu;DDS items to the Action Bar if it//is present. Getmenuinflater (). Inflate (R.menu.menu_main, menu); return true; }}
Run
Back to Catalog
27th Chapter: Layout
Types of layouts
- Linear layout
LinearLayout
: A linear layout is a view group (ViewGroup) that can line up all child elements in a single direction, either horizontally or vertically
- Relative layout
RelativeLayout
: A relative layout is a layout that displays a child view in a relative position
- Table layout
TableLayout
: Table layout is a view of grouping child elements in rows and columns
- Absolute layout
AbsoluteLayout
: Absolute layout allows you to specify the exact location of child elements
- Frame layout
FrameLayout
: Frame layout is a placeholder on the screen that you can use to display a single view
- List view
ListView
: The list layout is scrollable and is the view group used to display a list of child elements
- Grid view
GridView
: A grid view is a group of views that displays child elements in a two-dimensional scrollable grid
Back to Catalog
Task Four layout test
Task requirements
- Build the project, run the textbook related code
- Modify the layout so that the P290 page interface is different from the textbook
Experiment Code
activity_main.xml
<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:paddi ngleft= "2DP" android:paddingright= "2DP" > <button android:id= "@+id/cancelbutton" Android:layout_w Idth= "Wrap_content" android:layout_height= "wrap_content" android:text= "20165318" Android:layout_margi ntop= "70DP" android:layout_alignparenttop= "true" android:layout_centerhorizontal= "true"/> <button Android:id= "@+id/savebutton" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Sun Xiaolin" android:layout_below= "@+id/cancelbutton" android:layout_alignleft= "@+id/cancelBut Ton "android:layout_alignstart=" @+id/cancelbutton "android:layout_margintop=" 23DP "/> <imageview Android:layout_width= "150DP" android:layout_height= "150DP" android:layout_margintop= "45DP" android:padding= "4DP" android:src= "@andr Oid:drawable/presence_audio_away "android:id=" @+id/imageview "android:layout_below=" @+id/saveButton " Android:background= "@android: Color/white" android:layout_centerhorizontal= "true"/> <linearlayout a Ndroid:id= "@+id/filter_button_container" android:layout_width= "match_parent" android:layout_height= "Wrap_con Tent "android:layout_alignparentbottom=" true "android:gravity=" Center|bottom "android:background=" @an Droid:color/holo_blue_dark "android:orientation=" horizontal "> <button android:id=" @+id/fil Terbutton "android:layout_width=" wrap_content "android:layout_height=" Fill_parent "Androi d:text= "Open"/> <button android:id= "@+id/sharebutton" android:layout_width= "Wrap_conte NT "Android:layout_height= "Fill_parent" android:text= "Share"/> <button android:id= "@+id/deletebutto N "android:layout_width=" wrap_content "android:layout_height=" Fill_parent "android:text=" Delete "/> </LinearLayout></RelativeLayout>
Run
Back to Catalog
28th Chapter: Listener
- Android is event-based. User interaction with one view in an activity may trigger an event, including clicks, long presses, touches and keystrokes, and so on.
- To have a program respond to an event, you need to write a listener for the event. That is, to implement an interface embedded in the Android.view.View class. such as the OnClick () method of the Onclicklistener interface.
Back to Catalog
Task five: Event processing test
Task requirements
Run the textbook this chapter related code and
Experiment Code
I have made some changes in the textbook code, so that it can show my school number
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"/> <textview android:l Ayout_width= "Match_parent" android:layout_height= "match_parent" android:text= "20165318 Sun Xiaolin" Android:la Yout_marginleft= "70DP" android:layout_margintop= "300DP" android:textsize= "38DP" android:textcolor= "#bbbb00 "/></relativelayout>
Run
Back to Catalog
The problems encountered in the course of experiment and the solving methods
Back to Catalog
Experiment experience and experience
Back to Catalog
Code Hosting
Code Cloud Link
Back to Catalog
Psp
Back to Catalog
Resources
Android Development Easy Tutorial
Back to Catalog
# 20165318 2017-2018-2 "Java Programming" Fourth Week study summary