android 使用处理程序延迟
我想显示几个图像并在每个图像之间添加延迟。 我这样做了,代码中没有错误,但由于某种原因,应用程序崩溃了。
Bitmap bitmap = BitmapFactory.decodeFile(imageIn);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
// Those are the only 2 lines I used to make my handler
Handler handlerTimer = new Handler();
handlerTimer.postDelayed((Runnable) this, 20000);
I want to display a couple of images and add a delay between each image.
I did this and have no errors in the code but for some reason the app crashes.
Bitmap bitmap = BitmapFactory.decodeFile(imageIn);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
// Those are the only 2 lines I used to make my handler
Handler handlerTimer = new Handler();
handlerTimer.postDelayed((Runnable) this, 20000);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有说明哪个类托管您发布的代码片段,但我认为
handlerTimer.postDelayed((Runnable) this, 20000);
不太可能是正确的。尝试添加匿名
Runnable
对象,例如另一件事,
logcat
输出对于获取有关导致崩溃的原因的线索非常宝贵。 http://developer.android.com/guide/developing/tools/logcat.htmlYou don't say what class hosts the snippet you posted, but I think
handlerTimer.postDelayed((Runnable) this, 20000);
is unlikely to be right.Try adding an anonymous
Runnable
object such asAnother thing,
logcat
output is invaluable for getting clues about what is causing a crash. http://developer.android.com/guide/developing/tools/logcat.html