2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

androidタップした時に一瞬だけ画像を変える方法

Posted at

handler.postDelayedというのを使います。

imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //タップしたらすぐ動作するメソッド
                imageView.setImageResource(R.drawable.ossantapped);
                soundPool.play(soundOne, 1.0f, 1.0f, 0, 0, 1);

                //今回の記事で紹介した部分
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                     //処理内容はここに                    
                     imageView.setImageResource(R.drawable.ossan);
                    }
                }, 200);//1000ミリ秒 0.2秒後に行う処理

            }
        });

タップしたらimageViewにsetImageResource(R.drawable.ossantapped)を呼び出し、
handler.postDelayedの処理に移ります。
200m秒後に、setImageResource(R.drawable.ossan)が読まれる。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?