亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果用戶在測驗應用程序中回答 10 個問題,如何完成操作

如果用戶在測驗應用程序中回答 10 個問題,如何完成操作

UYOU 2022-05-12 16:15:40
我正在編寫一個簡單的測驗應用程序,類似于流行的應用程序誰想成為百萬富翁?一切都很順利,直到用戶回答第十個問題后我無法完成操作。我真正想要的是,在用戶回答 10 個問題后,我會顯示一條消息,說他們已經達到了第 10 個問題,但我無法做到這一點。public class MainActivity extends Activity implements View.OnClickListener{    TextToSpeech t1;    Button btn_one, btn_two, btn_three, btn_four;    TextView tv_question;    private Question question = new Question();       private String answer;    private int questionLength = question.questions.length;      Random random;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);         random = new Random();            btn_one = (Button)findViewById(R.id.btn_one);        btn_one.setOnClickListener(this);        btn_two = (Button)findViewById(R.id.btn_two);        btn_two.setOnClickListener(this);        btn_three = (Button)findViewById(R.id.btn_three);        btn_three.setOnClickListener(this);        btn_four = (Button)findViewById(R.id.btn_four);        btn_four.setOnClickListener(this);            tv_question = (TextView)findViewById(R.id.tv_question);        NextQuestion(random.nextInt(questionLength));        final String input = tv_question.getText().toString()        }    public void onPause() {        if (t1 != null) {            t1.stop();            t1.shutdown();        }        super.onPause();    }    @Override    public void onClick(View v) {        switch (v.getId()){            case R.id.btn_one:                if(btn_one.getText() == answer){                    Toast.makeText(MainActivity.this, "You Are Correct", Toast.LENGTH_SHORT).show();                    NextQuestion(random.nextInt(questionLength));                }else{                    GameOver();                }
查看完整描述

2 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

您可以添加一個計數器

Int counter = 0;

一旦用戶回答了一個問題,計數器就會增加。
然后你測試如果計數器 > 10 做任何你想做的事


查看完整回答
反對 回復 2022-05-12
?
holdtom

TA貢獻1805條經驗 獲得超10個贊

在 MainActivity 中:-


添加班級成員:-


int question_limit = 10;

int question_count = 0;

添加新方法


private void QuestionTen() {

    Toast.makeText(getApplicationContext(),"You have reached question 10.",Toast.LENGTH_SHORT);

}

在 NextQuestion 方法中添加一行,例如:-


if (question_count++ == question_limit) QuestionTen();


查看完整回答
反對 回復 2022-05-12
  • 2 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號