这是我的APIservice类(端点API调用类)
public interface WeatherService {
@GET("{latitude},{longitude}")
Call<Weather> getWeather(@Path("latitude") double d, @Path("longitude") double d2); }
这是我的网络请求电话
public class RetroCLient {
private static final String ROOT_URL = "https://api.forecast.io/forecast/api_id/";
private static Retrofit getRetrovitInstance() {
return new Retrofit.Builder()
.baseUrl(ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static WeatherService getApiService() {
return getRetrovitInstance().create(WeatherService.class);
} }
从服务器获取响应
getLoc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (InternetConnection.checkConnection(getApplicationContext())) {
final ProgressDialog dialog;
dialog = new ProgressDialog(MainActivity.this);
dialog.setTitle(getString(R.string.string_getting_json_title));
dialog.setMessage(getString(R.string.string_getting_json_message));
dialog.show();
WeatherService api = RetroCLient.getApiService();
Call<Weather> call = api.getWeather(getLat(),getLon());
/**
* Enqueue Callback will be call when get response...
*/
call.enqueue(new Callback<Weather>() {
@Override
public void onResponse(Call<Weather> call, Response<Weather> response) {
//Dismiss Dialog
dialog.dismiss();
if(response.isSuccessful()) {
/**
*
* Got Successfully
*/
dailylist = (ArrayList<Datum__>) response.body().getDaily().getData();
/**
* Binding that List to Adapter
*/
adapter = new DataAdapter(MainActivity.this, dailylist);
rowdata.setAdapter(adapter);
} else {
Snackbar.make(parentview, R.string.string_some_thing_wrong, Snackbar.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Weather> call, Throwable t) {
Log.d("shit","shit");
dialog.dismiss();
}
});
} else {
Snackbar.make(parentview, R.string.string_internet_connection_not_available, Snackbar.LENGTH_LONG).show();
}
}
});
但是当我尝试运行应用程序时,我没有从服务器获取数据.. 怎么了? :((
请帮帮我....