Retrofit - Multiple Calls using for
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm kinda new to android developing.
I'm using retrofit to make requests, but in one case I have a list of objects that I want to add to a database, doesn't need to return anything really. So I tried using "for" to do this but it only adds the last object even though all the objects are in the arraylist and using the debug it goes through the "for" as many times as that are objects in the arraylist. Here is the code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(APIService.URL_BASE)
.addConverterFactory(GsonConverterFactory.create())
.build();
for (int i = 0; i < horariosMarcados.size(); i++) {
APIService service = retrofit.create(APIService.class);
final Call<Horarios> requestReserva = service.reserva(horariosMarcados.get(i).getId_reserva(), numsala, horariosMarcados.get(i).getHorario(), horariosMarcados.get(i).getOcupado(), ReservaDetalhada_Popup.dia, processo, Login_Page.logado.getNome());
requestReserva.enqueue(new Callback<Horarios>() {
private static final String TAG = "reservaVic";
@Override
public void onResponse(Call<Horarios> call, Response<Horarios> response) {
Log.i(TAG, "TESTE: " + response.isSuccessful());
}
@Override
public void onFailure(Call<Horarios> call, Throwable t) {
Log.i(TAG, "Seu lixo!");
}
});
Is it possible to do it this way or do I have to use other libraries?
Many thanks!!
Regards,
java

add a comment |
I'm kinda new to android developing.
I'm using retrofit to make requests, but in one case I have a list of objects that I want to add to a database, doesn't need to return anything really. So I tried using "for" to do this but it only adds the last object even though all the objects are in the arraylist and using the debug it goes through the "for" as many times as that are objects in the arraylist. Here is the code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(APIService.URL_BASE)
.addConverterFactory(GsonConverterFactory.create())
.build();
for (int i = 0; i < horariosMarcados.size(); i++) {
APIService service = retrofit.create(APIService.class);
final Call<Horarios> requestReserva = service.reserva(horariosMarcados.get(i).getId_reserva(), numsala, horariosMarcados.get(i).getHorario(), horariosMarcados.get(i).getOcupado(), ReservaDetalhada_Popup.dia, processo, Login_Page.logado.getNome());
requestReserva.enqueue(new Callback<Horarios>() {
private static final String TAG = "reservaVic";
@Override
public void onResponse(Call<Horarios> call, Response<Horarios> response) {
Log.i(TAG, "TESTE: " + response.isSuccessful());
}
@Override
public void onFailure(Call<Horarios> call, Throwable t) {
Log.i(TAG, "Seu lixo!");
}
});
Is it possible to do it this way or do I have to use other libraries?
Many thanks!!
Regards,
java

2
are you sure that list has different entries? also sending your whole list in one go instead of calling service each time would be a good option.
– Karan Mer
Jan 3 at 12:15
Thanks! How would I do that? Do you mean just leaving the service outside of the for statement? Because I tried that but it also didn't work. Yes, I debugged it and it has all entries on the array list before going into the for statement.
– victorracy
Jan 3 at 12:46
change your service to be able to receive jsonarray. convert your arraylist to json array and send it over as request param.
– Karan Mer
Jan 3 at 13:01
add a comment |
I'm kinda new to android developing.
I'm using retrofit to make requests, but in one case I have a list of objects that I want to add to a database, doesn't need to return anything really. So I tried using "for" to do this but it only adds the last object even though all the objects are in the arraylist and using the debug it goes through the "for" as many times as that are objects in the arraylist. Here is the code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(APIService.URL_BASE)
.addConverterFactory(GsonConverterFactory.create())
.build();
for (int i = 0; i < horariosMarcados.size(); i++) {
APIService service = retrofit.create(APIService.class);
final Call<Horarios> requestReserva = service.reserva(horariosMarcados.get(i).getId_reserva(), numsala, horariosMarcados.get(i).getHorario(), horariosMarcados.get(i).getOcupado(), ReservaDetalhada_Popup.dia, processo, Login_Page.logado.getNome());
requestReserva.enqueue(new Callback<Horarios>() {
private static final String TAG = "reservaVic";
@Override
public void onResponse(Call<Horarios> call, Response<Horarios> response) {
Log.i(TAG, "TESTE: " + response.isSuccessful());
}
@Override
public void onFailure(Call<Horarios> call, Throwable t) {
Log.i(TAG, "Seu lixo!");
}
});
Is it possible to do it this way or do I have to use other libraries?
Many thanks!!
Regards,
java

I'm kinda new to android developing.
I'm using retrofit to make requests, but in one case I have a list of objects that I want to add to a database, doesn't need to return anything really. So I tried using "for" to do this but it only adds the last object even though all the objects are in the arraylist and using the debug it goes through the "for" as many times as that are objects in the arraylist. Here is the code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(APIService.URL_BASE)
.addConverterFactory(GsonConverterFactory.create())
.build();
for (int i = 0; i < horariosMarcados.size(); i++) {
APIService service = retrofit.create(APIService.class);
final Call<Horarios> requestReserva = service.reserva(horariosMarcados.get(i).getId_reserva(), numsala, horariosMarcados.get(i).getHorario(), horariosMarcados.get(i).getOcupado(), ReservaDetalhada_Popup.dia, processo, Login_Page.logado.getNome());
requestReserva.enqueue(new Callback<Horarios>() {
private static final String TAG = "reservaVic";
@Override
public void onResponse(Call<Horarios> call, Response<Horarios> response) {
Log.i(TAG, "TESTE: " + response.isSuccessful());
}
@Override
public void onFailure(Call<Horarios> call, Throwable t) {
Log.i(TAG, "Seu lixo!");
}
});
Is it possible to do it this way or do I have to use other libraries?
Many thanks!!
Regards,
java

java

asked Jan 3 at 12:08
victorracyvictorracy
1
1
2
are you sure that list has different entries? also sending your whole list in one go instead of calling service each time would be a good option.
– Karan Mer
Jan 3 at 12:15
Thanks! How would I do that? Do you mean just leaving the service outside of the for statement? Because I tried that but it also didn't work. Yes, I debugged it and it has all entries on the array list before going into the for statement.
– victorracy
Jan 3 at 12:46
change your service to be able to receive jsonarray. convert your arraylist to json array and send it over as request param.
– Karan Mer
Jan 3 at 13:01
add a comment |
2
are you sure that list has different entries? also sending your whole list in one go instead of calling service each time would be a good option.
– Karan Mer
Jan 3 at 12:15
Thanks! How would I do that? Do you mean just leaving the service outside of the for statement? Because I tried that but it also didn't work. Yes, I debugged it and it has all entries on the array list before going into the for statement.
– victorracy
Jan 3 at 12:46
change your service to be able to receive jsonarray. convert your arraylist to json array and send it over as request param.
– Karan Mer
Jan 3 at 13:01
2
2
are you sure that list has different entries? also sending your whole list in one go instead of calling service each time would be a good option.
– Karan Mer
Jan 3 at 12:15
are you sure that list has different entries? also sending your whole list in one go instead of calling service each time would be a good option.
– Karan Mer
Jan 3 at 12:15
Thanks! How would I do that? Do you mean just leaving the service outside of the for statement? Because I tried that but it also didn't work. Yes, I debugged it and it has all entries on the array list before going into the for statement.
– victorracy
Jan 3 at 12:46
Thanks! How would I do that? Do you mean just leaving the service outside of the for statement? Because I tried that but it also didn't work. Yes, I debugged it and it has all entries on the array list before going into the for statement.
– victorracy
Jan 3 at 12:46
change your service to be able to receive jsonarray. convert your arraylist to json array and send it over as request param.
– Karan Mer
Jan 3 at 13:01
change your service to be able to receive jsonarray. convert your arraylist to json array and send it over as request param.
– Karan Mer
Jan 3 at 13:01
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022003%2fretrofit-multiple-calls-using-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022003%2fretrofit-multiple-calls-using-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
are you sure that list has different entries? also sending your whole list in one go instead of calling service each time would be a good option.
– Karan Mer
Jan 3 at 12:15
Thanks! How would I do that? Do you mean just leaving the service outside of the for statement? Because I tried that but it also didn't work. Yes, I debugged it and it has all entries on the array list before going into the for statement.
– victorracy
Jan 3 at 12:46
change your service to be able to receive jsonarray. convert your arraylist to json array and send it over as request param.
– Karan Mer
Jan 3 at 13:01