Android Retrofit如何排序请求

时间:2016-07-08 13:03:28

标签: android retrofit

我从api获取数据并且我想要的不是全部,而是只有咖啡馆,餐馆等。我读到了关于@Query的信息,但dint将其放入。告诉我请问怎么做?谢谢。

改造:

public class Retrofit {

private static final String ENDPOINT = "http://gdetut.com/api";
private static ApiInterface apiInterface;

interface ApiInterface {
    @GET("/firms?salt=63926e380bdc96ef990d57898daeb71c&category_id=1")
    void getPlaces(Callback<List<Places>> callback);


}

static {
    init();
}

private static void init() {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(ENDPOINT)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();
    apiInterface = restAdapter.create(ApiInterface.class);
}

public static void getPlaces (Callback<List<Places>> callback) {
    apiInterface.getPlaces(callback);
}

}

活动:

Retrofit.getPlaces(new Callback<List<Places>>() {
        @Override
        public void success(List<Places> places, Response response) {


            listView.setAdapter(new MyAdapter(MainActivity.this, places));


        }

1 个答案:

答案 0 :(得分:0)

您想选择subcategory_id = 1吗? 尝试改变

//init and call
RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(ENDPOINT)
        .setLogLevel(RestAdapter.LogLevel.FULL)
        .build();
apiInterface = restAdapter.create(ApiInterface.class);
Call<List<Places>> call = ApiInterface.getPlaces("1");
call.enqueue(this);

//interface
interface ApiInterface {
@GET("/firms?salt=63926e380bdc96ef990d57898daeb71c&category_id=1")
Call<List<Places>> getPlaces(@Query("subcategory_id") String cat);
}

@Override
public void onResponse(Call<List<Places>> call, Response<List<Places>> response) {

    System.out.println("response " + response.toString());
}

@Override
public void onFailure(Call<List<Places>> call, Throwable t) {

}