I have the following codes. I am trying to get the TextView to display "Question 1: What is your name?" (the question text string stored in the String file), but now it is displaying "Question 1: 2131362201". How do I fix this? Thanks!
public class AnswerList {
private int mQuestion;
private int mAnswer;
public AnswerList(int question, int answer){
mQuestion = question;
mAnswer = answer;
}
}
public int getQuestion() {
return mQuestion;
}
private AnswerList[] mQuestionBank = new AnswerList[] {
new AnswerList(R.string.question1, R.string.answer1)
}
.....
int question = mQuestionBank[0].getQuestion();
mQuestionTextView.setText("Question 1:" + question);
getQuestion()
returns an int
, so you should expect the id
to be shown. In order to show the string resource associated with that id
, you need to call getString()
with a Context
(such as an Activity
):
String question = getString(mQuestionBAnk[0].getQuestion());