我试图多次调用我的函数,其中包含可运行对象。谁能告诉我我做错了什么?
handler = new Handler();
sButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
rounds = new Integer(et.getText().toString());
// handler.removeCallbacksAndMessages(null);
for (int j = 0; j <= rounds; j ++)
{
f();
}
}
});
}
public void f()
{
r = new Runnable()
{
@Override
public void run()
{
mp = MediaPlayer.create(Box.this, R.drawable.sound1);
mp.setLooping(false);
mp.setVolume(1.0f, 1.0f);
mp.start();
handler.postDelayed(this, 3000);
}
};
handler.postDelayed(r, 4000);
mp.stop();
提前致谢