Listing 2.5


#1

HELP ME PLEASE: how do i get rid of the red lines???

private TrueFalse[] mQuestionBank = new TrueFalse[] {
new TrueFalse(R.string.question_oceans, true),
new TrueFalse(R.string.question_mideast, false),
new TrueFalse(R.string.question_africa, false),
new TrueFalse(R.string.question_americas, true),
new TrueFalse(R.string.question_asia, true),
};

private int mCurrentIndex = 0;

private void updateQuestion() {
	int question = mQuestionBank[mCurrentIndex].getQuestion();
	mQuestionTextView.setText(question);
}

private void checkAnswer(boolean userPressedTrue) {
	boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();
	
	int messageRedId = 0;
	
	if (userPressedTrue == answerIsTrue) {
		messageResId = R.string.correct_toast;
	} else {
		messageResId = R.string.incorrect_toast;
	}
	
	Toast.makeText(this, messageResId, Toast.LENGTH_SHORT)
		.show();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);
    
    mQuestionTextView = (TextView)findViewById(R.id.question_text_view);
    
    mTrueButton = (Button)findViewById(R.id.true_button);
    mTrueButton.setOnClickListener(new View.OnClickListener() {
    	@Override
    	public void onClick(View v) {
    		checkAnswer(true);
    		//Does nothing yet, but soon!
    		
    	}
    });
    
    mFalseButton = (Button)findViewById(R.id.false_button);
    mFalseButton.setOnClickListener(new View.OnClickListener() {
    	@Override
    	public void onClick(View v) {
    		checkAnswer(false);
    		//Does nothing, but soon!
    		
    	}
    });
    
    mNextButton = (Button)findViewById(R.id.next_button);
    mNextButton.setOnClickListener(new View.OnClickListener() {
    	@Override
    	public void onClick(View v) {
    		mCurrentIndex = (mCurrentIndex +1) % mQuestionBank.length;
    	    updateQuestion();
    		
    	}
    });
    
    updateQuestion();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.quiz, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}