我正在做我的第一個Android應用程序,我想做一個測試應用程序,我正在使用一個變量和「If」/「Else如果「語句爲了改變問題文本(TextView)和答案(RadioButtons)。問題是,當用戶第一次按下按鈕時,答案和問題會改變,但當用戶第二次按下按鈕時,問題和答案不會改變,我不知道爲什麼...「否則如果」語句不做任何事(做一個Android測試)
這裏是我的活動:
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));
}
};
});
}
}
我試圖用「破發」,但問題仍然存在。
請幫忙。
'pregunta'總是'1',它永遠不會改變。嘗試'pregunta + = 1'或'pregunta ++' – Cody