我是新的改造,我想讓我的getData方法返回一個功能對象。什麼是最簡單的方法來做到這一點?如何從Retrofit onResponse方法返回數據?
DataService.java
public class DataService {
private static final String TAG = MainActivity.class.getSimpleName();
private final ApiClient apiClient;
public DataService() {
apiClient = new ApiClientFactory().createApiClient();
}
public List<Feature> getData(){
apiClient.getData().enqueue(new Callback<DataResponse>() {
@Override
public void onResponse(Call<DataResponse> call, Response<DataResponse> response) {
List<Feature> features = response.body().getFeatures();
Log.d(TAG, "Data successfully downloaded");
}
@Override
public void onFailure(Call<DataResponse> call, Throwable t) {
Log.e(TAG, t.toString());
}
});
//I need to return features in getData method
}
}
你的問題已經回答了有關http://stackoverflow.com/questions/34184088/how-can -i-return-value-from-function-on-retrofit – Rab
可能的重複[如何從函數onResponse的Retrofit返回值?](http://stackoverflow.com/questions/34184088/how-can- i-return-value-from-function-on-retrofit) – Rab
call.execute()。body() – uguboz