Ver Mensaje Individual
  #6  
Viejo 24/03/13, 17:48:55
Array

[xs_avatar]
androizado androizado no está en línea
Miembro del foro
 
Fecha de registro: dic 2012
Mensajes: 191
Modelo de smartphone: Nexus 5
Tu operador: Vodafone
kriogeN bien logre lo que me dijiste hacerlo creando AsyncTask, antes de seguir comentando mi siguiente problema, GRACIAS POR EL CONSEJO DE USAR ASYNCTASK, pero mi problema es que sigo sin lograr traer los datos del servicio web creado en PHP que son estos:

 Cita:
{ "libros" : [ { "id" : 1, "libro": "Don Quijote de la Mancha", "isbn": "978-84-8427-800-9" } , { "id" : 2, "libro": "La Celestina", "isbn": "978-84-87876-39-4 " } , { "id" : 3, "libro": "El esperpento", "isbn": "978-84-85178-27-8" } , { "id" : 4, "libro": "Manolito Gafotas", "isbn": "978-84-204-5807-6" } ] }
A ver si alguien me podría echar una manilla con el código a poner en el metodo doInBackground(), esto es lo que estoy haciendo:

 Cita:
@Override
protected Boolean doInBackground(Void... params) {

for(int i=1; i<=10; i++) {
tareaLarga();
publishProgress(i*10);
}
HttpResponse resp = httpClient.execute(url);
String respStr = EntityUtils.toString(resp.getEntity());

JSONArray respJSON = new JSONArray(respStr);

String[] peliculas = new String[respJSON.length()];

for(int i=0; i<respJSON.length(); i++){
JSONObject obj = respJSON.getJSONObject(i);

String titLib = obj.getString("libro");
String isbnLib = obj.getString("isbn");

peliculas[i] = titLib + " - " + isbnLib;
}

ArrayAdapter<String> adaptador =
new ArrayAdapter<String>(Peliculas.this,
android.R.layout.simple_list_item_1, peliculas);

lstPeliculas.setAdapter(adaptador);
return true;
}
y en el metodo onCreate():

 Cita:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

listView1 = (ListView)findViewById(R.id.listView1);

HttpClient httpClient = new DefaultHttpClient();
HttpGet url = new HttpGet("http://192.168.0.11/android/libros/service.libros.php");

url.setHeader("content-type", "application/json");

pDialog = new ProgressDialog(MainActivity.this);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPIN NER);
pDialog.setMessage("Actualizando datos...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();

tarea2 = new MiTareaAsincronaDialog();
tarea2.execute();
}

Como siempre GRACIAS DE ANTEMANO por las respuestas
Responder Con Cita