2012-07-30 3 views
0

이 코드를 가지고 있습니다 :
openHandlera = new ViDBOpenHandler (this); 내 이미지가 imageArrr 동일한 경우 [1], 다음 일초 음악을 재생하고 시간을 시작하는 현재 시간을 설정하는 것이 말하고 싶은이 코드에서특정 이미지가 나타나면 음악을 재생하십시오.

  Runnable ru = new Runnable(){  
      public void run(){  

       int imageArrr[] = new int[2];  
       imageArrr[0] = R.drawable.crossone;  
       imageArrr[1] = R.drawable.blackone;  

       int n = (int)(Math.random()*2);  

       theIm.setImageResource(image[n]);  
       if(n == 0) {  
        Log.v("Result", "n is 0 now");  
        startTimea = System.currentTimeMillis();  
        final SoundGenerator task=new SoundGenerator();  
        task.keepPlaying(true);  
        task.setLoudness(audioLoudnessa);  
        task.execute(audioFrequencya);  

        new Handler().postDelayed(new Runnable() {  
          public void run()   {       
          task.keepPlaying(false);  
         }  
        }, 1000);  
       }  
       new Handler().postDelayed(new Runnable() {  
        public void run() {      

         finish();  
        }  
       }, 30000);  

        Log.v("test", "is"+ startTimea);  
        theIm.postDelayed(this, 3000); //set to go off again in 3 seconds.  
      }  
     };  
     theIm.postDelayed(ru,1500);   

. 문제는 if (n == 0)을 사용한다는 것입니다. 그러나 그것은 그것이 구현하는 방법을 인식하지 못하는 것 같습니다. 그것은 doesnt 한 경우에 간다. 그리고 나는 소리를들을 수 없다. 그리고 심지어 그것은 아무것도 인쇄하지 않는다. 아무도 나에게 무엇을해야한다고 안내 할 수 있습니까?

답변

1
int n = (int)(Math.random()*2);  

당신은 무작위로 n의 값을 생성하고 당신은 제로

그래서 당신의 상태 if(n == 0)이 결코 참이 없습니다 언제든지 못하고있다. 당신은 적절한 결과를 얻지 못하고 있습니다.

편집 : 당신이

if(n>2> 
    int image =imageArrr[0]; 
else 
    int image =imageArrr[1]; 
+0

처럼 사용할 수 있습니다하지만 imageArrr 사이의 임의의 이미지를 가지고 싶어 [0] imageArrr [1]. 그럼 어떻게해야합니까 무작위로 사용해야합니까? 내 상태를 어떻게 설정해야합니까? – androidGirl

+0

인덱스 때문에 n이 0 또는 1이 될 수있는 것과 같지 않습니까? plz 가이드 나를. – androidGirl

+0

내 수정 된 답변보기 – MAC

관련 문제