public class TrueFalseActivity extends Activity implements View.OnClickListener{
Button buttonClicked = null;
List<QuestionTrueFalse> questionTrueFalseList;
int myscore = 0;
int quid=0;
int id ;
TextView tv, tv1;
QuestionTrueFalse curQues;
Button b1, b2;
Button next, back;
Button button;
QuestionTrueFalse cur;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trfal);
tv=(TextView) findViewById(R.id.tv1);
b1=(Button) findViewById(R.id.b1);
b2=(Button) findViewById(R.id.b2);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
DbHelper db = new DbHelper(this);
questionTrueFalseList = db.getAllTrFalsQuestions();
if (questionTrueFalseList != null && questionTrueFalseList.size() != 0) {
curQues = questionTrueFalseList.get(quid);
try {
setQuestionView();
}catch (NullPointerException e)
{
Toast.makeText(getApplicationContext(),"Exception caught",Toast.LENGTH_LONG).show();
}
}
next=(Button) findViewById(R.id.forw);
back=(Button) findViewById(R.id.back);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button=(Button) v;
String buttonText=button.getText().toString();
if(curQues.getAnsw().equals(buttonText))
{
myscore++;
}
cur=curQues;
if(quid<19){
quid++;
curQues=questionTrueFalseList.get(quid);
setQuestionView();
}else{
Intent intent = new Intent(TrueFalseActivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", myscore); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
});
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (quid > 0) {
quid--;
curQues = questionTrueFalseList.get(quid);
setQuestionView();
}
}
});
private void setQuestionView() {
tv.setText(curQues.getQues());
b1.setText(curQues.getOpt1());
b2.setText(curQues.getOpt2());
}
public void onClick(View v) {
// final Button button;
button=(Button) v;
String buttonText=button.getText().toString();
enter code here
//Button is set red if answer is correct..
if (curQues.getAnsw().equals(buttonText))
{
button.setBackgroundColor(Color.GREEN);
myscore++;
}
//Button will be set to red if answer is false
else
{
button.setBackgroundColor(Color.RED);
}
if(quid>19){
countDownTimer.cancel();
timerHasStarted = false;
Intent intent = new Intent(TrueFalseActivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", myscore); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
}
我正在開發測驗應用程序,它有兩個按鈕,一個onClick()。我點擊了一個按鈕,然後點擊下一個相同的顏色被轉到下一個按鈕。當我點擊下一個按鈕時, 如何清除按鈕顏色。 我應該如何清除進行下一個問題的顏色?我是android新手。任何人都可以幫助我解決這個問題。提前致謝。如何清除按鈕的顏色,當我點擊下一步按鈕?
改變按鈕的顏色,同時單擊下一步按鈕 –