我想每2秒更改一次List
中的图片(其发布者路径存储在Imageview
中),我尝试使用Handler
和一个线程来更改,但是我的应用程序崩溃了。
这是我的代码:
@Override
protected void onStart() {
super.onStart();
/** Calling this method for upcoming movies**/
Call<HomePageRespons> callUpcoming=apiInterface.
getUpcomingMovie(API_KEY);
callUpcoming.enqueue(new Callback<HomePageRespons>() {
@Override
public void onResponse(Call<HomePageRespons> call,
Response<HomePageRespons> response) {
int statusCode=response.code();
int pos=0;
final List<HomePage> list2=response.body().getResult();
int totalresult=response.body().getTotalResult();
Picasso.get().load("https://image.tmdb.org/t/p/w500"+
list2.get(pos).getPosterPath()).into(poster1);
pos++;
if(pos!=totalresult) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
onStart();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
t.start();
}
}
@Override
public void onFailure(Call<HomePageRespons> call, Throwable t) {
Log.e(TAG,t.toString());
}
});
}