0

私は最初のAndroidアプリを作成していて、テストアプリを作成したいのですが、質問のテキスト(TextView)と回答(RadioButtons)を変更するために、変数と「If」/「Elseif」ステートメントを使用しています。 )。問題は、ユーザーが最初にボタンを押すと回答と質問が変わるのに、ユーザーが2回目にボタンを押すと質問と回答が変わらず、理由がわからないことです...

これが私の活動です:

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」を使ってみましたが、問題は解決しません。

助けてください。

4

1 に答える 1

3

1クリックイベントごとに変数に追加するには、代わりにこれを使用してみてください。

pregunta++;

(これはまたはと同じであることを理解してpregunta += 1;くださいpregunta = pregunta + 1;


あなたが書いたことは、それがただのことをpregunta = + 1;意味しますpregunta = +1;

pregunta = 1;
于 2012-10-02T22:41:47.650 に答える