Android Project Development----Geoquiz

Source: Internet
Author: User

Geoquiz Project Summary:

    • Objective

This project is the first application developed for this semester, through which we can learn some basic Android concepts and the UI components that make up the app. This blog is also my first time since learning programming formally completed the first blog, is still very plain and jerky.

    • Development environment

This project uses the Androidstudio as the development environment.

First we need to create this project in Androidstudio, the project name is Geoquiz.

    • Start a new Android Studio project in Androidstudio

    • Project name is Geoquiz

    • Select an empty page

    • Then go on to next and choose Finish, and an empty project package gets better.

    • This project requires the following directory

    • Code writing

The first thing we need to do is to implement the user interface, this project mainly uses the vertical and horizontal linearlayout components, the TextView component and the button component. In the text interface we can quickly write component code to achieve more efficient layout, the project has a total of two activities, and three layout views including the rotatable view, we can see the completion of the layout as follows:

We've set up listeners for all button controls, all of them using anonymous internal classes, so we can implement listener methods relatively centrally and without tedious creation of named classes, we could feel the implementation code:

  • <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/true_button"/>
  • <resources ><string name=  "app_name" >geoquiz</string A.. <string name= "True_button" >true</string A.. </resources>          
  • <Button        android:id="@+id/true_button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/true_button"/>
  • class QuizActivity extends AppCompatActivity {private Button mTrueButton;...}
  •  public class quizactivity extends AppCompatActivity {private button mtruebutton; @Override protected void OnCreate (bundle savedinstancestate) { Span class= "Hljs-keyword" >super.oncreate (savedinstancestate); Setcontentview (button) Findviewbyid ( R.id.true_button)}}               
  •   ...  @Override protected void oncreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_quiz); MTrueButton = ( Button) Findviewbyid (R.id.true_button); Mtruebutton.setonclicklistener (new View.onclicklistener () { @Override  public void onClick (View v) {//Does nothing yet, but soon!}}); Mfalsebutton = (Button) Findviewbyid (R.id.false_button);}}          

< Span class= "Hljs-title" >

< Span class= "Hljs-title" > It is important to note that model objects cannot interact directly with view objects. The controller acts as a link between them, the receiving object sends the message, and then sends the operation instruction to the other object.

    • Then we use the MVC design pattern.

We can start by simply knowing:

The full name of MVC is the Model View controller, which is the abbreviation for Models-View-controller, a software design paradigm .

    • Model--is the part of the application that handles application data logic. Typically model objects are responsible for accessing data in the database
    • View--is the part of the application that handles the display of data. Typically views are created from model data.
    • Controller--is the part of the application that handles user interaction. Usually the controller is responsible for reading data from the view, controlling user input, and sending data to the model.

Advantages of using MVC.

    • Low coupling-The view layer is detached from the business layer, allowing changes to the view layer code without recompiling the model and controller code
    • High reusability-Multiple views can share a model
    • Low life cycle costs--MVC reduces the technical content of developing and maintaining user interfaces.

Combine the code to gain a deeper understanding of:

public class Question {
private int mtextresid;
Private Boolean manswertrue;

Public Question (int textresid, Boolean answertrue) {
Mtextresid = Textresid;
Manswertrue = Answertrue;
}

public int Gettextresid () {
return mtextresid;
}
public void Settextresid (int textresid) {
Mtextresid = Textresid;
}
public Boolean isanswertrue () {
return manswertrue;
}
public void Setanswertrue (Boolean answertrue) {
Manswertrue = Answertrue;
}
}

    • Life cycle of activity

Each android has its life cycle, during which the activity is converted in four states of running, pausing, stopping, and not running. Each time the state transitions, there are corresponding activity methods to notify the activity of the message. Shows the lifecycle, state, and method of system calls for the activity's life cycle, status, and state transitions.

Activity is managed by the activity stack, and when it comes to a new activity, the activity is added to the top of the activity stack, and the activity is at the bottom of the activity. There are four states in the general sense of acitivity:

    • 1. When the activity is at the top of the stack, it is in the front of the screen at this time and is in a running state;
    • 2. When the activity loses focus but remains on the visible (such as the top of the activity is transparent or the top of the stack activity is not covered with the entire phone screen), at this time in a paused state;
    • 3. When activity is completely obscured by other activity, the activity is not visible to the user at this time and is in a stopped state;
    • 4. When the activity is destroyed due to human or system reasons (such as low memory, etc.), it is in the destruction state at this time;

In each of the different state stages, the adnroid system callbacks the corresponding methods within the activity. Therefore, when we write activity in the program, we generally inherit the activity class and rewrite the corresponding callback method.

Android Project Development----Geoquiz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.