change to:
protected void onPostExecute(Pair p)
{
list.setAdapter(p.result);
mTxtView1.setText(p.asignatura);
}
And in doInBackground:
Pair p=new Pair();
try{
JSONArray arrayJson = new JSONArray(resultado);
for(int i= 0; i<arrayJson.length();i++){
JSONObject objetoJson = arrayJson.getJSONObject(i);
alum = new mostrar_alumnos(objetoJson.getInt("id_alumno"), objetoJson.getString("nombre"), objetoJson.getString("apellidos"));
JSONObject objetoJson2 = arrayJson.getJSONObject(arrayJson.length()-1);
String asignatura = new mostrar_curso_clase_asignatura(objetoJson2.getInt("curso"), objetoJson2.getString("clase"), objetoJson2.getString("asignatura")).toString();
//mTxtView1.setText(asignatura);
listaalumnos.add(alum);
p.asignatura=asignatura;
}
}catch (JSONException e){
e.printStackTrace();
}
ArrayAdapter<mostrar_alumnos> adaptador = new ArrayAdapter<mostrar_alumnos>(contexto, android.R.layout.simple_list_item_1, listaalumnos); //Contexto de ver clientes (Muestra la lista con los datos de clientes que le he pasado
p.result=adaptador;
return p;
}
Extend you class with following:
AsyncTask<Params, Progress, Result>
Here last type is return type of doInBackgorund as well as argument of onPostExecute so change this to Pair
as you are returning a Pair
object.
change to:
static class Tarea1 extends AsyncTask<ListView, Void, Pair>
{
Context contexto;
ListView list;
InputStream is;
ArrayList<mostrar_alumnos> listaalumnos = new ArrayList<mostrar_alumnos>();
public void cargarContenido (Context contexto)
{
this.contexto= contexto;
}
@Override
protected Pair doInBackground(ListView... params)
{