0
在MainActivity.java //根URL我們的Web服務的 公共靜態最後絃樂ROOT_URL =「http://pratikbutani.x10.mx」; RestAdapter adapter = new RestAdapter.Builder() .setEndpoint(ROOT_URL) .build();成敗方法不調用使用改裝Android中
//Creating an object of our api interface
BooksAPI api = adapter.create(BooksAPI.class);
//Defining the method
api.getBooks(new Callback<List<Contact>>() {
@Override
public void success(List<Contact> list, Response response) {
//Dismissing the loading progressbar
//Storing the data in our list
books = list;
//Calling a method to show the list
showList();
}
@Override
public void failure(RetrofitError error) {
//you can handle the errors here
}
});
公共接口BooksAPI {
/*Retrofit get annotation with our URL
And our method that will return us the list ob Book
*/
@GET("/json_data.json")
public void getBooks(Callback<List<Contact>> response);
}
我應該在哪裏放置代碼//調用代碼。 –
在您的活動或片段中(或者如果您遵循MVP架構,則爲演示者) –