我正在处理一个Android应用程序,其中我希望每5秒后更改背景图像。我有我的可绘制文件夹中的所有图像。如何在几秒钟后自动更改背景图片?
我给我正在使用的代码,但我没有得到输出。作为输出,我得到一个不变的静止图像。
请帮
感谢
[CODE]
public class Home extends Activity {
public static int count=0;
int[] drawablearray=new int[]{R.drawable.slider_1,R.drawable.slider_2,R.drawable.slider_3,R.drawable.slider_4,R.drawable.slider_5};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
new Handler().postDelayed(new Runnable() {
public void run() {
if(count<drawablearray.length){
Home.this.getWindow().
setBackgroundDrawableResource(drawablearray[count]);
count++; //<<< increment counter here
}
else{
// reset counter here
count=0;
}
}
}, 5000);
}
}
得到一个错误,把这个中的onCreate –
@AkshaySethi ..什么是错误?我只是在这里写了大致 – stinepike
作了两个小改动,请现在检查 – stinepike