I'm trying to show the results of my Json in an AlertDialog, using the AsyncTask class, I managed to process the url, but I have no idea how to show the final results within a listView, in my onPostExecute ... Some help for favor there is my code ...
new AsyncTask<String, String, String>() {
AlertDialog.Builder alertdialogbuilder ;
protected void onPreExecute() {
super.onPreExecute();
alertdialogbuilder = new AlertDialog.Builder(getActivity());
alertdialogbuilder.setTitle("Que Lineas Desees?");
}
@Override
protected String doInBackground(String... strings) {
// alertdialogbuilder.setTitle("De Que Lineas ?");
final String url = "http://mirUrl.com";
prod = new ArrayList<>();
HttpHandler sh = new HttpHandler();
JSONObject jsonStr = sh.makeServiceCall(url);
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(String.valueOf(jsonStr));
JSONArray contacts = jsonObj.getJSONArray("CATEGORIAS");
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String descripcion = c.getString("nombre");
HashMap<String, String> contacto = new HashMap<>();
contacto.put("nombre", descripcion);
prod.add(contacto);
Log.d("REGLON", String.valueOf(prod));
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
// aca deberia mostrar el resultado final supongo...
AlertDialog dialog = alertdialogbuilder.create();
dialog.show();
}
}.execute();