Chapter 2: pg 42, listing 2.7 question


#1

In listing 2.7, page 42, why is question an int?

mQuestionTextView=(TextView)findViewById(R.id.question_text_view);
int question=mQuestionBank[mCurrentIndex].getTextResId();
mQuestionTextView.setText(question);

Thanks.


#2

Because it is assigned to something (the following getTextResId() method) that returns a number. Question in this case is not a string, but rather a reference id number. The reference id is correlated with a string, which is in turn the question text that we see on the application.

Kind of reminds me how an IP address, which is a number, is also correlated with a URL, which is a string.


#3

When I write this code, my application Crashes.
I turned this into mQuestionTextView.setText(Integer.toString(question)); and it shows 0 but not the question text.
Any solution ?