【问题标题】:Repeated random number questions重复的随机数问题
【发布时间】:2015-02-20 21:12:59
【问题描述】:

我有以下课程需要向用户显示随机问题。

但是我的问题是班级只显示一个问题而不是连续提问。 我怎样才能重复用户的问题以保留他们的问题!分数? 见下图 -

public class Chooser extends ActionBarActivity implements View.OnClickListener {

    int randomOne = 0;
    int randomTwo = 0;
    int problems = 0;
    int sum = 0;
    int userAnswer = 0;
    int correct = 0;
    int inCorrect = 0;
    int userInput, result;

    TextView question, response, answer, report;
    EditText userNumber;
    Button ans;
    private Random add;


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

        question = (TextView) findViewById(R.id.question);
        response = (TextView) findViewById(R.id.response);
        answer = (TextView) findViewById(R.id.answers);
        report = (TextView) findViewById(R.id.report);
        userNumber = (EditText) findViewById(R.id.answer);
        ans = (Button) findViewById(R.id.button);
        ans.setOnClickListener(this);
        add = new Random();
        randomOne = add.nextInt(20);
        randomTwo = add.nextInt(10);
        Display();

    }

    public void Display() {
        sum = randomOne + randomTwo;
        question.setText(randomOne + " +  " + randomTwo);
    }

    @Override
    public void onClick(View v) {
        userInput = Integer.parseInt(userNumber.getText().toString());
        Log.e("getting user input", "" + userInput);

        if (userInput == sum) {

            response.append(" CORRECT! , You are the best \n");

            correct++;
        } else {

            response.append("INCORRECT, The correct answer was  :" + sum + "\n");

            inCorrect++;
        }

        problems++;


    }


}

【问题讨论】:

    标签: android random textview


    【解决方案1】:

    我不确定我是否理解您的问题,但假设您希望每次单击“提交”按钮时向用户显示不同的“问题”,您应该在单击按钮后调用“Display()”方法并生成通过将每次 randomOne &randomTwo 设置为 nextInt(some_number) 的新随机数...希望这会有所帮助..

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      相关资源
      最近更新 更多