Actualización de datos de Json analizados en Listview

He estado intentando almacenar los datos analizados de Json en Listview pero no está trabajando.

Recuperé algunos datos (que está en la forma de tabla) de un servidor y después lo analizé en el objeto de Json. El código entero funcionó bien. Muestra los datos recuperados cuando uso "Toast" en mi actividad de Android. Por favor, ayúdame a almacenar estos datos analizados en ListView.

Aquí está mi código

public void clickbutton(View v) { try { // Log.i(getClass().getSimpleName(), "send task - start"); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC); // HttpParams p = new BasicHttpParams(); // p.setParameter("name", pvo.getName()); p.setParameter("user", "1"); // Instantiate an HttpClient HttpClient httpclient = new DefaultHttpClient(p); String url = "http://bhavit.xtreemhost.com/webservice1.php?user=1&format=json"; HttpPost httppost = new HttpPost(url); // Instantiate a GET HTTP method try { Log.i(getClass().getSimpleName(), "send task - start"); // List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>( 7); nameValuePairs.add(new BasicNameValuePair("details", "1")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httppost, responseHandler); // Parse JSONObject json = new JSONObject(responseBody); JSONArray jArray = json.getJSONArray("posts"); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < jArray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject e = jArray.getJSONObject(i); String s = e.getString("post"); JSONObject jObject = new JSONObject(s); map.put("time", jObject.getString("time")); map.put("latitude", jObject.getString("latitude")); map.put("longitude", jObject.getString("longitude")); mylist.add(map); } Toast.makeText(this, responseBody, Toast.LENGTH_LONG).show(); **String[] columns = new String[] { "Time", "Latitude", "Longitude" }; int[] renderTo = new int[] { R.id.time, R.id.latitude, R.id.longitude }; ListAdapter listAdapter = new SimpleAdapter(this, mylist, R.layout.geo_ponts_list, columns, renderTo); setListAdapter(listAdapter);** } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Log.i(getClass().getSimpleName(), "send task - end"); } catch (Throwable t) { Toast.makeText(this, "Request failed: " + t.toString(), Toast.LENGTH_LONG).show(); } } private void setListAdapter(ListAdapter listAdapter) { // TODO Auto-generated method stub } public class Data { // private List<User> users; public List<details> users; // +getters/setters } static class details { String latitude; String longitude; String time; public String Longitude() { return longitude; } public String Latitude() { return latitude; } public String Time() { return time; } public void setUserName(String value) { longitude = value; } public void setidusers(String value) { latitude = value; } 

No hay ningún error, pero la actividad no muestra los valores en el ListView, pero los valores se pueden ver usando Toast.! Producción de actividad usando tostadas

Aquí está mi archivo geo_ponts_list.xml

 <TextView android:id="@+id/time" android:textSize="16sp" android:textStyle="bold" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/latitude" android:textSize="16sp" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/longitude" android:textSize="16sp" android:layout_width="fill_parent" android:layout_height="wrap_content"/> 

Primera cosa a mencionar:

Compruebe nuevamente que su HashMap obtiene los valores correctos o no,

Registre sus valores en su bucle for como Log.i("item",jObject.getString("time"));

Y la segunda cosa hacer su propia custom list Adapter clase,

USANDO ESTE EJEMPLO IGUAL QUE EL SUYO

Parece que el SimpleAdapter que estás usando debería ser sensible a mayúsculas y minúsculas? Estás pasando "Time", "Latitude" y "Longitude" como tus columnas, pero tu objeto JSON contiene "time", "latitude" y "longitude".

He dado su código de ir, y como Quenton dijo, es el problema con el caso que hace que el listview no mostrar nada.

 **String[] columns = new String[] { "Time", "Latitude", "Longitude" }; int[] renderTo = new int[] { R.id.time, R.id.latitude, R.id.longitude }; ListAdapter listAdapter = new SimpleAdapter(this, mylist, R.layout.geo_ponts_list, columns, renderTo); setListAdapter(listAdapter);** 

Debe modificar columnas variable para tener los valores en mayúsculas. Funcionó para mí.

 String[] columns = new String[] {"time", "latitude', 'longitude'}; 
  • OutOfMemoryError cuando se utiliza Gson para analizar una gran respuesta JSON
  • Cómo convertir json objeto en cadena en android ..?
  • Conexión de Android a localhost
  • Google Services Plugin no puede funcionar sin google-services.json
  • Sólo el hilo original que creó una jerarquía de vistas puede tocar su excepción de vistas
  • GSON evitar el JsonSyntaxException devolver el mapeo parcial
  • Deserialización de JsonArray y JsonObject de Android
  • Anónimo Subir objeto de archivo a la API Imgur (JSON) da error de autenticación 401
  • Cómo configurar gson para excluir 0 valores enteros
  • No se puede resolver el símbolo JSONParser
  • UnitTest JSONObject muestra null
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.