zoukankan      html  css  js  c++  java
  • 我为儿子开发的第一款Android App,用于九九乘法练习

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

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

    github下载地址:https://github.com/sinodragon21/MultiplicationTable.git

    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)+"
    "+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的截图如下:

  • 相关阅读:
    生日蜡烛
    生日蜡烛
    Angular2 and Electron
    NW.js and Electron compared
    Github发布了为桌面应用开发而生的Electron 1.0版本(HTML、CSS和JavaScript)
    哈佛——教育
    国家的强大——小学教师
    (OK)(OK) Fedora23——NS3(MANETs)——Docker(busybox)——genymotion(android)——All is OK
    (OK) ns3—genymotion—android
    android——adb shell——netcfg——get IP address
  • 原文地址:https://www.cnblogs.com/sinodragon21/p/14237049.html
Copyright © 2011-2022 走看看