我想显示几张图片并在每张图片之间添加延迟。 我这样做并且代码中没有错误,但由于某种原因应用程序崩溃了。
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);
最佳答案
您没有说明您发布的代码 fragment 所在的类,但我认为 handlerTimer.postDelayed((Runnable) this, 20000);
不太可能是正确的。
尝试添加一个匿名的 Runnable
对象,例如
handlerTimer.postDelayed(new Runnable(){
public void run() {
// do something
}}, 20000);
另一件事,logcat
输出对于获取有关导致崩溃的原因的线索非常宝贵。 http://developer.android.com/guide/developing/tools/logcat.html
关于android延迟使用处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5623578/