나는 이미지를 질문으로 사용하고 간단한 이미지를 선택으로 사용하는 간단한 퀴즈 앱을 개발 중입니다. 여기서 문제는 제가 오류가 무엇입니까 int 유형의 mAnswer에 형 이미지 뷰입니다 선택 assinging하고 때어떻게 ImageView를 android의 등호 연산자로 적용 할 수 있습니까?
는연산자 '==는'android.widget '에 적용 할 수 없습니다 .imageView ','int '
ImageView를 int에 직접 할당 할 수 없다는 것을 알고 있습니다. 선택을위한 이미지 리소스를 얻으려고했지만 이미지 리소스에 직접 액세스 할 수있는 방법을 찾을 수 없습니다.
public class counting extends AppCompatActivity {
ImageView choice_one;
private Questions mQuestions = new Questions();
private int mAnswer;
private int mQuestionsLength = mQuestions.mQuestions.length;
Random r;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_counting);
r = new Random();
choice_one=(ImageView)findViewById(R.id.choice_1);
question=(ImageView)findViewById(R.id.question);
updateQuestions(r.nextInt(mQuestionsLength));
choice_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(choice_one == mAnswer){
mp=MediaPlayer.create(counting.this,R.raw.bird);
mp.start();
updateQuestions(r.nextInt(mQuestionsLength));
}else{
mp=MediaPlayer.create(counting.this,R.raw.april);
mp.start();
}
}
});
}
private void updateQuestions(int num){
question.setImageResource(mQuestions.getQuestion(num));
choice_one.setImageResource(mQuestions.getChoice1(num));
mAnswer = mQuestions.getAnswer(num);
}
}
Question.class
public class Questions {
public int mQuestions[]={
R.drawable.onee, R.drawable.twoe, R.drawable.threee,
R.drawable.foure, R.drawable.sixe, R.drawable.eighte
};
public int mChoices[][]={
{R.drawable.counting_one, R.drawable.counting_two, R.drawable.counting_three, R.drawable.counting_four},
{R.drawable.counting_one, R.drawable.counting_two, R.drawable.counting_three, R.drawable.counting_four},
{R.drawable.counting_one, R.drawable.counting_two, R.drawable.counting_three, R.drawable.counting_four},
{R.drawable.counting_one, R.drawable.counting_two, R.drawable.counting_three, R.drawable.counting_four},
{R.drawable.counting_one, R.drawable.counting_two, R.drawable.counting_six, R.drawable.counting_four},
{R.drawable.counting_one, R.drawable.counting_eight, R.drawable.counting_three, R.drawable.counting_four}
};
public int mAnswers[]={R.drawable.counting_one,R.drawable.counting_two,R.drawable.counting_three,
R.drawable.counting_four, R.drawable.counting_six, R.drawable.counting_eight};
public int getQuestion(int a){
int question = mQuestions[a];
return question;
}
public int getChoice1(int a){
int choice = mChoices[a][0];
return choice;
}
public int getChoice2(int a){
int choice = mChoices[a][1];
return choice;
}
public int getChoice3(int a){
int choice = mChoices[a][2];
return choice;
}
public int getChoice4(int a){
int choice = mChoices[a][3];
return choice;
}
public int getAnswer(int a){
int answer = mAnswers[a];
return answer;
}
}
'ImageView'가 '42'와 같은 것은 무엇을 의미합니까? – azurefrog
42는 무엇을 의미합니까? – danish
https://www.quora.com/Why-and-how-is-42-the-answer-to-life-the-universe-and-everything – Henry