簡體   English   中英

我將在Android中開發一個新的Quiz應用程序。 當我單擊錯誤的選項時,它必須顯示紅色,我們該怎么做?

[英]I am going to develop a new Quiz application in Android. When I click on the wrong option it has to show red color how can we do that?

我是這個測驗應用程序的新手。

我在這里使用單選按鈕。 當我單擊錯誤的選項時,它將變為紅色,並且還必須顯示正確的答案。 現在這是我的代碼。 當我單擊下一個按鈕時,它將顯示如下。 提前致謝。 這里的合計,正確和錯誤是靜態變量,用於顯示另一個班級的最終分數。

            RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
            String ansText = uans.getText().toString();

            if (ansText.equalsIgnoreCase(answers[flag])) {


                correct++;
            } else {



                wrong++;
            }
            flag++;

            if (flag < question.length) {
                tv.setText(question[flag]);
                rb1.setText(options[flag * 3]);
                rb2.setText(options[flag * 3 + 1]);
                rb3.setText(options[flag * 3 + 2]);
                marks = correct - wrong;

            } else {
                marks = correct - wrong;
                Intent in = new Intent(getApplicationContext(),
                        ResultActivity.class);
                startActivity(in);

            }
            if (flag == question.length) {
                Intent in = new Intent(getApplicationContext(),
                        ResultActivity.class);
                startActivity(in);
                Level1Activity.this.finish();
            }
            total = question.length;

在發現錯誤的ans的地方添加這些語句,即在其他地方需要設置紅色的地方。

如果您的color.xml是這樣的:

<color name="errorColor">#f00</color>

然后

uans.setTextColor(getResources().getColor(R.color.red));

並設置另一種顏色的ans

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM