0
My code does not load the data to list view when ta inside the AsyncTask
, but if it is placed in the onCreateView
works perfectly.
public class Tab_os_Fechadas extends Fragment {
private String url ="http://redeml.no-ip.info/controleos/mobile/list_os_fechadas.php";
private String parametros ="";
private ListView listOSFechadas;
private int i;
private LayoutInflater inflater;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View x = inflater.inflate(R.layout.tab_os_fechada,null);
new SolicitarDados().execute(url);
return x;
}
private class SolicitarDados extends AsyncTask<String, Void,String > {
View view;
@Override
protected String doInBackground(String... urls) {
return ConexaoDB.postDados(urls[0], parametros);
}
@Override
protected void onPostExecute(String result) {
try {
JSONArray jsonarray = new JSONArray(result);
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
}
ArrayList<ItemOSFechadas> listaFechada = new ArrayList<ItemOSFechadas>();
ItemOSFechadas a = new ItemOSFechadas("g1","ffff");
ItemOSFechadas b = new ItemOSFechadas("g1","ffff");
ItemOSFechadas c = new ItemOSFechadas("g1","ffff");
ItemOSFechadas d = new ItemOSFechadas("g1","ffff");
listaFechada.add(a);
listaFechada.add(b);
listaFechada.add(c);
listaFechada.add(d);
ListAdapterOSFechadas adapterOSFechadas = new ListAdapterOSFechadas(getContext(),listaFechada);
listOSFechadas = (ListView)view.findViewById(listFechadasOS);
listOSFechadas.setAdapter(adapterOSFechadas);
}catch (JSONException e) {
e.printStackTrace();
}
}
}
}
My intention is to make my JSON return and assemble my entire list view.
I tried that way, and it didn’t work. my listview does not appear the data I create, my Requested function is usually executed, but not the data from listview
– Mateus Soares
can hit, and working ok , but I went to test on mobile and listview did not load, but in emulator android studio uploaded, how can I identify the problem ?
– Mateus Soares
It’s pretty hard to tell from just looking at this piece of code. Try sending your project to github and provide the link so I can try to identify your problem.
– jefferson