【发布时间】:2012-04-07 14:33:55
【问题描述】:
我使用这个 android 代码,当用户触摸屏幕时,振动开始并持续 3000 毫秒。我不希望用户总是触摸屏幕,振动的持续时间与以前的时间(3000 毫秒)相同。我想使用随机,每次振动持续随机时间。根据我的代码我应该如何使用随机?
请帮帮我。
public boolean dispatchTouchEvent(MotionEvent ev)
{
if (ev.getAction() == MotionEvent.ACTION_UP)
{
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(3000);
}
return super.dispatchTouchEvent(ev);
}
【问题讨论】: