Write a simple mobile app

Write a simple mobile phone APP

The relevant code has been uploaded to: https://github.com/XinzeWu/firstAPP
portal

I have nothing to do and want to count as a marriage, so I wrote a Zhouyi fortune-telling app. Let’s start now!


Preface

With the help of the tool Android Studio
, let’s not say much, let’s take a few renderings first

Insert picture description here
Enter the content you want to fortune, and then click to start the fortune. The
Insert picture description here
final result, the image of the hexagram, and the change of the line are all things that the metaphysics master will interpret.
But code = metaphysics
I write code, so: I = metaphysics master
interprets this One hexagram means not great, so happy to be single! ! !


Text time is up:

One, the installation of Android Studio

The predecessor’s narration is complete, directly on the link of a great god:
super detailed super multi-picture installation Android Studio

This is how it looks like when the installation is successful. See if my interface feels refreshed. .
Insert picture description here

2. Graphical programming

Heavy: xml interface can be used without code!

Insert picture description here
Look at this interface, all positions can be directly dragged, text can be added directly here, of course, can also be defined in the string

I will talk about the definition of this string later

Three.js files are also super simple

First import a bunch of package
codes as follows (example):

package com.example.myfirstapp;


import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

Then start a start interface, open activate_main.xml

    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

Then I defined a function to interface with button events

@RequiresApi(api = Build.VERSION_CODES.O)
    public void sendMessage(View view) {
    
    
        //EditText editText = findViewById(R.id.editText);
        change();
        setContentView(R.layout.activity_display_message);
        TextView textView1 = findViewById(R.id.gua_name);
        textView1.setText(data.guaName);

        TextView textView2 = findViewById(R.id.yao_name);
        textView2.setText(data.changeYao);

        TextView textView3 = findViewById(R.id.yao_web);
        textView3.setText(data.guaExp);


    }

For data transmission, I directly defined a class, which can be shared in the package, but it is better not to define it as public.
Develop good code habits

package com.example.myfirstapp;

class data {
    
    
    static String guaName;
    static String changeYao;//包括可变的爻以及对应解释的卦
    static String guaExp;
}

Return button event

@RequiresApi(api = Build.VERSION_CODES.O)
    public void getBack(View view){
    
    
        setContentView(R.layout.activity_main);
    }

As for the string on xml, there is no problem directly entering it, but the reusable and easy-to-change feature of programming makes me instinctively want to define it in the string.xml file

<resources>
    <string name="app_name">周易算卦</string>
    <string name="edit_message">输入您想占卜的对象</string>
    <string name="button_send">开始算卦</string>
</resources>

Actually so easy!

Four. Problems encountered

This sentence is crazy. I have indeed defined editText in the xml file, but adding this sentence will crash and cry.

EditText editText = findViewById(R.id.editText);

Will there be great gods who will solve this problem? Old rules, please drink autumn milk tea!


to sum up

The Android APP I wrote, finally iterated out the second version, pleased

Thanks for the encouragement of YZY sister

Thanks to my good brother XJH for the help and the closed beta test done by many good brothers

Guess you like

Origin blog.csdn.net/qq_44647796/article/details/109255970