我正在使用Retrofit。并且call.enqueue
以异步方式执行。我有一个代码块,只有在call.enqueue
成功执行后才能执行。
call.enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
returnedEvent = response.body();
}
@Override
public void onFailure(Call<Event> call, Throwable t) {
Toast.makeText(ViewEventActivity.this, "There was some internal error. Please try again!", Toast.LENGTH_SHORT).show();
}
});
//code block to be executed after the thread has been executed.
mTitle = (TextView) findViewById(R.id.event_title);
mStartTime = (TextView) findViewById(R.id.startsAt);
mEndTime = (TextView) findViewById(R.id.endsAt);
mEventTitle.setText(event.getTitle());
提前致谢!
答案 0 :(得分:2)
当onResponse or onFailure
被执行时意味着call.enqueue
已成功执行。您应该在此处添加您的区块。
call.enqueue(new Callback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
returnedEvent = response.body();
//code block to be executed after the thread has been executed.
mTitle = (TextView) findViewById(R.id.event_title);
mStartTime = (TextView) findViewById(R.id.startsAt);
mEndTime = (TextView) findViewById(R.id.endsAt);
mEventTitle.setText(event.getTitle());
}
@Override
public void onFailure(Call<Event> call, Throwable t) {
Toast.makeText(ViewEventActivity.this, "There was some internal error. Please try again!", Toast.LENGTH_SHORT).show();
}
});