我为儿子开发的第一款Android App,用于九九乘法练习

用一天时间在macbook上安装好了Android Studio For Mac,注意dl.google.com只支持电信网络下载,家里宽带如果是移动或者联通的,使用AS下载Android SDK和后面新建project下载gradle时网络都有问题(移动宽带无法直接下载,需要设置代理proxy)

今天用不到一天时间,为儿子开发的第一款Android App,用于九九乘法练习

package com.nathan.multiplicationtable;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    int factor = 1, factorBase = 9;
    int faciend = 1, faciendBase = 9;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        refreshQuestion();
    }

    public void calculateMT(View view){
        EditText editTextAnswer = findViewById(R.id.editTextAnswer);
        TextView textViewHints = findViewById(R.id.textViewHints);
        int answer = Integer.parseInt(String.valueOf(editTextAnswer.getText()));
        if(answer == factor * faciend) {
            textViewHints.setText(R.string.right);
        }else{
            String strHints = String.format("%d x %d = %d", factor, faciend, factor*faciend);
            textViewHints.setText(this.getString(R.string.wrong)+"\n"+strHints);
        }
    }

    public void nextQuestion(View view){
        refreshQuestion();
    }

    void refreshQuestion(){
        Random rand = new Random();
        factor = rand.nextInt(factorBase) + 1;
        faciend = rand.nextInt(faciendBase) + 1;
        // String question = Integer.toString(factor) + "x" + Integer.toString(faciend) + "=";
        TextView textViewA = findViewById(R.id.textViewA);
        TextView textViewB = findViewById(R.id.textViewB);
        EditText editTextAnswer = findViewById(R.id.editTextAnswer);
        TextView textViewHints = findViewById(R.id.textViewHints);
        textViewA.setText(Integer.toString(factor));
        textViewB.setText(Integer.toString(faciend));
        editTextAnswer.setText("");
        textViewHints.setText("");
    }
}

APP的截图如下:

我为儿子开发的第一款Android App,用于九九乘法练习

我为儿子开发的第一款Android App,用于九九乘法练习

上一篇:R语言Error


下一篇:【转载】 Pytorch(0)降低学习率torch.optim.lr_scheduler.ReduceLROnPlateau类