2017-10-10 2 views
-1

나는 이미지를 질문으로 사용하고 간단한 이미지를 선택으로 사용하는 간단한 퀴즈 앱을 개발 중입니다. 여기서 문제는 제가 오류가 무엇입니까 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; 
} 

}

+0

'ImageView'가 '42'와 같은 것은 무엇을 의미합니까? – azurefrog

+0

42는 무엇을 의미합니까? – danish

+0

https://www.quora.com/Why-and-how-is-42-the-answer-to-life-the-universe-and-everything – Henry

답변

0

직접 등호를 사용하여 이미지를 비교할 수 없습니다. 비트 맵 이미지를 다른 이미지와 비교하는 것보다 비트 맵으로 변환하는 것보다 이미지를 비교하는 것이 좋습니다. 좋은 비트 맵을 사용합니다. 하지만 속도가 느려질 수 있습니다. 모두가 당신의 QUES과 답변을 imageviews 및 getTag 비교에 예를 들어 이미지를 비교하는이 Answer

또는

다른 방법을 확인하는 것은 setTag입니다.

+0

대략 일 수 있습니다. 그것이 필요로하는 것보다 천 배 느리다. OP는 정답을 클릭했는지 확인하려고합니다. – Henry

+0

예, 속도가 느려질 수 있습니다. –

+0

작동하지 않습니다. – danish