Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Java &引用;否则,如果;对账单don';什么都不做(做一个android测试)_Java_Android_Eclipse_If Statement_Statements - Fatal编程技术网

Java &引用;否则,如果;对账单don';什么都不做(做一个android测试)

Java &引用;否则,如果;对账单don';什么都不做(做一个android测试),java,android,eclipse,if-statement,statements,Java,Android,Eclipse,If Statement,Statements,我正在制作我的第一个android应用程序,我想制作一个测试应用程序,我正在使用一个变量和“If”/“Else If”语句来更改问题(TextView)和答案(单选按钮)的文本。问题是,当用户第一次按下按钮时,答案和问题会改变,但当用户第二次按下按钮时,问题和答案不会改变,我不知道为什么 以下是我的活动: package com.example.test; import android.app.Activity; import android.os.Bundle; import android

我正在制作我的第一个android应用程序,我想制作一个测试应用程序,我正在使用一个变量和“If”/“Else If”语句来更改问题(TextView)和答案(单选按钮)的文本。问题是,当用户第一次按下按钮时,答案和问题会改变,但当用户第二次按下按钮时,问题和答案不会改变,我不知道为什么

以下是我的活动:

package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class Test extends Activity {

TextView titulo;
RadioGroup buttons;
RadioButton opcn1;
RadioButton opcn2;
RadioButton opcn3;
RadioButton opcn4;

int pregunta = 0;

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

    titulo = (TextView) findViewById(R.id.textView1);

    buttons = (RadioGroup) findViewById(R.id.radioGroup1);

    opcn1 = (RadioButton) findViewById(R.id.radio0);
    opcn2 = (RadioButton) findViewById(R.id.radio1);
    opcn3 = (RadioButton) findViewById(R.id.radio2);
    opcn4 = (RadioButton) findViewById(R.id.radio3);


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


        @Override
        public void onClick(View v) {

            pregunta = + 1;

            if (pregunta == 1){ 

                titulo.setText(getString(R.string.Q2));
                opcn1.setText(getString(R.string.Q2O1));
                opcn2.setText(getString(R.string.Q2O2));
                opcn3.setText(getString(R.string.Q2O3));
                opcn4.setText(getString(R.string.Q2O4));

            }
            else if (pregunta == 2){

                titulo.setText(getString(R.string.Q3));
                opcn1.setText(getString(R.string.Q3O1));
                opcn2.setText(getString(R.string.Q3O2));
                opcn3.setText(getString(R.string.Q3O3));
                opcn4.setText(getString(R.string.Q3O4));

            }
        };

    });
}
}
我尝试使用“break”,但问题仍然存在


请提供帮助。

要在每次单击事件中将
1
添加到变量中,请尝试使用以下选项:

pregunta++;
(理解这与
pregunta+=1;
pregunta=pregunta+1;


你所写的
pregunta=+1表示
pregunta=+1这只不过是

pregunta = 1;

要在每次单击事件中将
1
添加到变量中,请尝试改用此选项:

pregunta++;
(理解这与
pregunta+=1;
pregunta=pregunta+1;


你所写的
pregunta=+1表示
pregunta=+1这只不过是

pregunta = 1;

pregunta
始终是
1
,它从不改变。尝试
pregunta+=1
pregunta++
pregunta
总是
1
,它从不改变。请尝试
pregunta++=1
pregunta++
谢谢!我还在学习,我忘了“pregunta=+1;”总是将“1”设置为变量“pregunta”,而不是将“1”添加到变量中。现在我的测试工作很好()谢谢!谢谢!我还在学习,我忘了“pregunta=+1;”总是将“1”设置为变量“pregunta”,而不是将“1”添加到变量中。现在我的测试工作很好()谢谢!