Geoquiz Project Summary
Develop an application called Geoquiz by learning the basic concepts of Android and the basic components that make up the application. The purpose of the application is to test the user's geographic knowledge. The user clicks the true or False button to answer questions on the screen, and Geoquiz can instantly respond to the correct answer.
Pre-development preparation work
To develop an Android app, start by developing software on your PC. Android Studiois recommended here, and all of this development is done on the platform.
The installation of Android Studio includes:
1.Android SDK
The latest version of the Android SDK.
2.Android SDK tools and Platform tools
A set of tools to test and debug your application.
3.Android Simulator System Mirroring
Used to develop test applications on different virtual devices.
Download and installAndroid studio:https://developer.android.com/sdk/can be downloaded from the Android developer website. For the first installation, you will also need to download and install the Java Developer Kit (JDK7) from http://www.oracle.com. If you still have installation problems, please visit the URL https://developer.android.com/sdk/for help. Download the previous version of Sdkandroid studio with the latest version of the SDK and system emulator image. However, if you want to test your app on an earlier version of Android, you will need to download the relevant tool components. You can configure the installation of these components through the Android SDK manager. In Android Studio, select the To O LS→ANDROID→SDK Manager menu item, shown in 0-1. 0-1 andriod SDK Manager Select and install the required Android version and tools. It takes some time to download these components, please be patient. With the Android SDK Manager, you can also get the latest Android releases, such as new system platforms or new versions of tools. Creation of application development 1.1 projects
First, open Android Studio and create the Geoquiz project.
Then there is a directory for this project. Such as:
1.2 Code writing 1.2.1 Interface design
The interface required for this project is shown below.
1.2.2 Source
First, the settings are handled in Spring.xml.
1<resources>2<string name= "App_name" >GeoQuiz</string>3 4<string name= "True_button" >TRUE</string>5<string name= "False_button" >FALSE</string>6<string name= "Next_button" >NEXT</string>7<string name= "Prev_button" >PREV</string>8<string name= "Correct_toast" >Correct!</string>9<string name= "Incorrect_toast" >Incorrect!</string>Ten<string name= "Warning_text" >are you sure your want to Do This?</string> One<string name= "Show_answer_button" >show answer</string> A<string name= "Cheat_button" >Cheat!</string> -<string name= "Judgment_toast" >cheating is wrong.</string> -<string name= "Question_oceans" >the Pacific Ocean is larger than the Atlantic ocean.</string> the<string name= "Question_mideast" >the Suez Canal connects the Red Sea and the Indian ocean.</string> -<string name= "Question_africa" >the source of the Nile River are in egypt.</string> -<string name= "Question_americas" >the Amazon River was the longest river in the americas.</string> -<string name= "Question.asia" >lake Baikal is the world\ ' s oldest and deepest freshwater lake.</string> +</resources>
Implement from layout to view in Quizactivity.java.
1 @Override2 protected voidonCreate (Bundle savedinstancestate) {3 Super. OnCreate (savedinstancestate);4LOG.D (TAG, "onCreate (Bundle) called");5 Setcontentview (R.layout.activity_quiz);6 7 if(Savedinstancestate! =NULL) {8Mcurrentindex = Savedinstancestate.getint (key_index, 0);9 }Ten OneMquestiontextview =(TextView) Findviewbyid (R.id.question_text_view); A -Mtruebutton =(Button) Findviewbyid (R.id.true_button); -Mtruebutton.setonclicklistener (NewView.onclicklistener () { the @Override - Public voidOnClick (View v) { -Checkanswer (true); - } + }); -Mfalsebutton =(Button) Findviewbyid (R.id.false_button); +Mfalsebutton.setonclicklistener (NewView.onclicklistener () { A @Override at Public voidOnClick (View v) { -Checkanswer (false); - } - }); - -Mnextbutton =(Button) Findviewbyid (R.id.next_button); inMnextbutton.setonclicklistener (NewView.onclicklistener () { - @Override to Public voidOnClick (View v) { +Mcurrentindex = (mcurrentindex + 1)%mquestionbank.length; -Mischeater =false; the updatequestion (); * } $ });Panax Notoginseng -Mprevbutton =(Button) Findviewbyid (R.id.prev_button); theMprevbutton.setonclicklistener (NewView.onclicklistener () { + @Override A Public voidOnClick (View v) { theMcurrentindex = (mCurrentIndex-1)%mquestionbank.length; + updatequestion (); - } $ }); $ -Mcheatbutton =(Button) Findviewbyid (R.id.cheat_button); -Mcheatbutton.setonclicklistener (NewView.onclicklistener () { the @Override - Public voidOnClick (View v) {Wuyi BooleanAnsweristrue =mquestionbank[mcurrentindex].ismanswertrue (); theIntent Intent = cheatactivity.newintent (quizactivity. This, answeristrue); - Startactivityforresult (Intent, request_code_cheat); Wu } - }); About $ updatequestion (); - -}
In the Question.java model layer code
1 Public classQuestion {2 Private intMtextresid;3 Private Booleanmanswertrue;4 5 PublicQuestion (intTextresid,Booleananswertrue) {6Mtextresid =Textresid;7Manswertrue =answertrue;8 }9 Ten Public intGetmtextresid () { One returnMtextresid; A } - - Public voidSetmtextresid (intMtextresid) { the This. Mtextresid =Mtextresid; - } - - Public Booleanismanswertrue () { + returnmanswertrue; - } + A Public voidSetmanswertrue (Booleanmanswertrue) { at This. Manswertrue =manswertrue; - } -}
1.3 Android and Mac design mode shows the interactive control data flow between objects when responding to events such as a user clicking a button. Note that model objects do not interact directly with view objects. The controller acts as a link between them, receives the message sent by the object, and sends an operation instruction to the other object.
Creates an array object that, by interacting with TextView and buttons, displays the problem on the screen and responds to the user's answer.
The life cycle of the 1.4 activity
State diagram of activity
1.5 A second activity
Component code in the Activity_cheat.xml
1<?xml version= "1.0" encoding= "Utf-8"?>2 3<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"4Xmlns:tools= "Http://schemas.android.com/tools"5Android:layout_width= "Match_parent"6android:layout_height= "Match_parent"7android:orientation= "Vertical"8android:gravity= "Center"9tools:context= "Classroom.geoquiz.CheatActivity" >Ten One<TextView AAndroid:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" -Android:padding= "24DP" theandroid:text= "@string/warning_text"/> - -<TextView -Android:layout_width= "Wrap_content" +android:layout_height= "Wrap_content" -Android:id= "@+id/answer_text_view" +Android:padding= "24DP" Atools:text= "Answer"/> at -<Button -Android:id= "@+id/show_answer_button" -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" -android:text= "@string/show_answer_button"/> in -</LinearLayout>
A second activity was created to make it easier for users to see the answer.
This is a component of the second activity.
1.6 Activating activity
To start the activity you need to pass the StartActivity () method.
Intent Intent = cheatactivity.newintent (quizactivity. this, answeristrue); Startactivityforresult (Intent, request_code_cheat);
Android Project Development--geoquiz Project Summary