0
Although there is already a similar question, not clarified my doubt, my problem is the following, the code below is from onResponse of Retrofit, I’m starting now in Java, I would like to play the result of Response.body in listview, i managed by doing a for in stringlist.add(countryList.get(i) code. getNome()), however I would like to know if there would be a better way to do it, I saw some examples using Course, but my requests will return about 1400 lines so I do not know if using is can compromise performance, thought if there could not be another more elegant way to do, in the code below I tried to play the List with the direct Replay.body() in Arrayadapter, only that this way the app returns the data so:
public void onResponse(Call < List < Funcionarios >> call, Response < List < Funcionarios >> response) {
try {
List < String > stringList = new ArrayList < > ();
ListView lista = (ListView)findViewById(R.id.ListView);
TextView qtdtotal = (TextView) findViewById(R.id.textView);
List < Funcionarios > countryList = response.body();
ArrayAdapter adapter = new ArrayAdapter < > (getApplicationContext(), android.R.layout.simple_list_item_1, countryList);
lista.setAdapter(adapter)
} catch (Exception e) {
Log.d("onResponse", "There is an error");
e.printStackTrace();
}
@GET("/webservice/webservice.php")
Call < List < Funcionarios >> getFunc(@Query("empresa") String empresa);
public class Funcionarios{
@SerializedName("NOME")
private String nome;
@SerializedName("MAT")
private int matricula;
@SerializedName("EMP")
private int empresa;
private List<Funcionarios> lsfunc = null;
public List<Funcionarios> getFunc() {
return lsfunc;
}
public void setFunc(List<Funcionarios> posts) {
this.lsfunc = posts;
}
public int getMatricula() {return matricula ; }
public int getEmpresa() {
return empresa ;
}
public String getNome() {
return nome;
}
public void setMatricula(){
this.matricula = matricula;
}
public void setNome(){
this.nome = nome;
}
public void setEmpresa(){
this.empresa = empresa;
}
}
The ideal would then be to work with paging. Instead of returning all results at once, make a request limiting the amount of items. Ai as you scroll, you will make a new request with another "package" of items.
– viana
So, the list in my case is to improve the interaction, because I think to implement a filter that shows the result in the list...but in case I can not do it, because in the case that this received data will be inserted in the sqlite, only that with the list would be better to check if the filter went well.
– Dunga Cardoso
I put an answer explaining over an idea of how it could be done. = D
– viana