我有这个代码:
openHandlera = new ViDBOpenHandler(this);
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);
在这段代码中,我想说如果我的图像等于 imageArrr[1],则播放音乐一秒钟并将当前时间设置为开始时间。问题是我使用了 if(n==0)。但似乎它不承认这种实施方式。因为它不去如果,我听不到声音,甚至它不打印任何东西。有人可以指导我该怎么做吗?