1)修改strings.xml
<string name="question_oceans">1The Pacific Ocean is larger than the Atlantic Ocean</string>
<string name="question_mideast">2The Suez Canal connects the Red Sea and the Indian Ocean</string>
<string name="question_africa">3the source of the nile River is in Egypt</string>
<string name="question_americas"> 4the amazon river is the longest river in the USA</string>
<string name="question_asia">5Lake Baikal is the world\'s oldest and deepest freshwater lake</string>
<string name="correct_toast">Correct</string>
<string name="incorrect_toast">Incorrect</string>
2)修改按钮监听方法
mFalseButton=(Button)findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
checkAnswer(false);
}
});
mNextButton = (Button)findViewById(R.id.next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCurrentIndex=(mCurrentIndex+1)%mQuestionsBank.length;
updateQuestion();
}
});
3)增加checkAnswer方法
private void checkAnswer(boolean userPressedTrue){
boolean answerIsTrue =mQuestionsBank[mCurrentIndex].isAnswerTrue();
int messageResId=0;
if (userPressedTrue==answerIsTrue){
messageResId=R.string.correct_toast;
}else{
messageResId=R.string.incorrect_toast;
}
Toast.makeText(this,messageResId,Toast.LENGTH_SHORT).show();
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30046312/viewspace-2137135/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30046312/viewspace-2137135/