为什么分数不能正确更新我的测验应用程序

时间:2017-05-21 22:21:30

标签: java android

我是Java / Android开发的新手,我正在试图找出为什么我的分数在我的模拟器上没有正确更新。如果这很明显,我很抱歉 - 但我无法弄明白(即使经过大量研究)。这是我的代码:

package org.flinthill.finalprojectv3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.text.method.DigitsKeyListener;
import android.text.InputFilter;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    int Score = 0;


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

        Button SuSe;
        Button DOS;
        Button B;
        Button BIOS;

        //int Score = 0;

        SuSe = (Button) findViewById(R.id.SuSe);
        SuSe.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(), "Wrong!", 
Toast.LENGTH_SHORT).show();
                Score = Score * 0;

            }
        });
        DOS = (Button) findViewById(R.id.DOS);
        DOS.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(), "Wrong!", 
Toast.LENGTH_SHORT).show();

                Score = Score * 0;

            }
        });

        B = (Button) findViewById(R.id.B);
        B.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(), "Wrong!", 
Toast.LENGTH_SHORT).show();

                Score = Score * 0;

            }
        });
        BIOS = (Button) findViewById(R.id.BIOS);
        BIOS.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(), "Right!", 
Toast.LENGTH_SHORT).show();

                Score = Score ++;

            }
        });
    }
}

1 个答案:

答案 0 :(得分:2)

您应该使用Score++;Score = Score + 1; 而不是Score = Score ++;