N
N
newdancer2016-02-24 21:21:40
Java
newdancer, 2016-02-24 21:21:40

How to call Callback() from Fragment for Retrofit?

How to call Callback() from Fragment to call Retrofit call interface?
In the fragment in onCreateView I wrote:

// Создаем адаптер с базовым адресом
        RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(SOURCE).build();
        // Создаём сервис
        API api = restAdapter.create(API.class);
        api.getCinema(API_TOKEN, new Callback() {
            @Override
            public void success(KinoModel kinoModel, Response response) {
                // Получаем ввиде json и конвертируем
                cinemas.add(new Cinema(kinoModel.getTitleRU()));
            }
            @Override
            public void failure(RetrofitError error) {
                Log.d("myLogs", "Failed!!!");
            }
        });

the interface itself looks like this:
public interface API
{
    @GET("/serial_updates.json")
    void getCinema(@Query("api_token") String api_token, Callback response);
}

throws an error on Calback():
is not abstract and does not override abstract method success(Object,Response) in Callback

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Zagaevsky, 2016-02-24
@newdancer

Callback is generic. You didn't parametrize it.
new Callback<KinoModel>(){ ... }

I
Ilya Pavlovsky, 2016-02-26
@TranE91

I strongly recommend switching to Retrofit2 in advance.

N
newdancer, 2016-02-24
@newdancer

in what format does retrofit get the result when the array updates???
tried to do so

@Expose
private List<Upd> updates;
public List<Upd> getUpdates()
{
return updates;
}
public class Upd {
@SerializedName("title_ru")
private String title_ru;
}

the result is a code like: package [email protected]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question