こんにちは、初めての投稿ですのでお手柔らかにお願いします。私のアンドロイドの最終版は完成しましたが、楽しみのためだけにプログラムを調整して追加し続けないのは難しいと思います。それは簡単なプログラムで、画面をタッチすると、画面上のキャラクターが 2 つの方法のうちの 1 つで、それに合わせた振動で笑います。それはうまく機能しますが、私の先生(当時は機嫌が悪かった)がテストに行ったとき、彼はボタンを押すたびにキューを作るものをほとんどボタンマッシュアップし、15回の笑いが収まるまで座っていなければなりませんでした電話でもっと何でもします。私がやりたいことは、最初のイベントが完了するまでワンタッチイベントをカウントすることです。これは単純な on touch イベントで、ネストされた if ステートメントがいくつかあります。
public boolean onTouch(final View v, MotionEvent m)
{
v.setBackgroundResource(R.drawable.laughing);//changes the image to the laughing monkey
if (m.getAction() == MotionEvent.ACTION_DOWN)
{
if (timesTouched != I) //checks to see if the touch amount is not equal to the random number
{
if(laughter != 0)
{
sp.play(laughter, 1, 1, 1, 0, 1);//plays the loaded sound when the screen is pressed
//vib.vibrate(900);
}
Time = 900;
timesTouched++;
intDelay = 1;
if(vibon == 1)
{
vib.vibrate(Time);
}
}
else if (timesTouched == I)//checks to see if the touch amount is the same as the random number
{
if(laughter != 0)
{
sp.play(laughFit, 1, 1, 1, 0, 1);//plays the loaded sound when the screen is pressed
}
Time = 6000;
timesTouched = 0;
intDelay = 1;
if(vibon == 1)
{
vib.vibrate(laugh, -1);
}
}
}
else if((m.getAction() == MotionEvent.ACTION_UP) && (intDelay == 1))
{
try {
Thread.sleep(Time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
v.setBackgroundResource(R.drawable.normal) ;//returns the image to the normal looking monkey
intDelay = 0;
}
return true;
}
}
スリープ タイマーは、笑いが終わる前に背景画像がデフォルトに戻るのを防ぐためにあります。私は先生に助けを求めようとしましたが、彼はただの迅速な交代であり、今年の初めに教え始めるまでアンドロイドデバイスに触れたことさえありませんでした. これまでのところ、Google検索の助けを借りてこのことを独学で学ばなければならなかったので、あなたが提供できる助けがあれば大歓迎です.
本当にありがとう!