Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运营商赢得';Android/Java Calculator应用程序中的t函数_Java_Android_Mobile - Fatal编程技术网

运营商赢得';Android/Java Calculator应用程序中的t函数

运营商赢得';Android/Java Calculator应用程序中的t函数,java,android,mobile,Java,Android,Mobile,我刚开始学习移动开发的第一个学期,在课程流程上遇到了一些问题。我可以理解Java以及程序的逻辑,但是我在实现它时遇到了困难 我所拥有的:按钮在文本视图中显示数字,可以按运算符,但计算不起任何作用。我的计算器应该是滚动计算器,即:输入:1+1=2(显示/保持)+1(自动显示:3);calculate(=)很可能在给定序列中只按一次,操作员将执行该功能。firstNum+secondNum=result->firstNum=secondNum,secondNum=0->result???不确定 这是

我刚开始学习移动开发的第一个学期,在课程流程上遇到了一些问题。我可以理解Java以及程序的逻辑,但是我在实现它时遇到了困难

我所拥有的:按钮在文本视图中显示数字,可以按运算符,但计算不起任何作用。我的计算器应该是滚动计算器,即:输入:1+1=2(显示/保持)+1(自动显示:3);calculate(=)很可能在给定序列中只按一次,操作员将执行该功能。firstNum+secondNum=result->firstNum=secondNum,secondNum=0->result???不确定

这是我的MainActivity.java;我已经为strings.xml中的所有按钮和文本创建了资源,所以我认为这些都很好

      btnAdd.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            operatorSwitch = 1;
            numPressed = false; // able to add numbers

            if(pressed){ // if this is not the first calculation:
                 // total becomes firstNum

                secondNum = Double.parseDouble(display); // secondNum is new input
                total = firstNum + secondNum; // calculate new total
                display = Double.toString(total);
                txtCalculation.setText(display);
                numPressed = true; // Can't add numbers to mess with current total

            }else{ // first calculation
                firstNum = Double.parseDouble(display);
                display = "";
                txtCalculation.setText(display);}
        }
    });



btnCalculate.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                secondNum = Double.parseDouble(display);
                while(pressed == false){
                if (operatorSwitch == 1) {
                    total = firstNum + secondNum;
                    display = Double.toString(total);
                    txtCalculation.setText(display);
                    pressed = true;
                    firstNum = total;
                    numPressed = true;
                }
编辑:只是寻找正确方向的指针和代码的一般流程,因为我已经把自己弄糊涂了

edit2:我无法让add函数以我的方式工作,它不断地添加总数,而不允许我进行第二次输入