Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Parsed Json data into Listview
    primarykey
    data
    text
    <p>I've been trying to store the parsed Json data into Listview but it's not working.</p> <p>I retreived some data(which is in the form of table) from a server and then i parsed it into Json object. The whole code worked well. It displays the retreived data when i use 'Toast' in my android activity. Please help me to store this parsed data in Listview.</p> <h2>Here is my code</h2> <pre><code>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&amp;format=json"; HttpPost httppost = new HttpPost(url); // Instantiate a GET HTTP method try { Log.i(getClass().getSimpleName(), "send task - start"); // List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;( 7); nameValuePairs.add(new BasicNameValuePair("details", "1")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httppost, responseHandler); // Parse JSONObject json = new JSONObject(responseBody); JSONArray jArray = json.getJSONArray("posts"); ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); for (int i = 0; i &lt; jArray.length(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); 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&lt;User&gt; users; public List&lt;details&gt; 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; } </code></pre> <hr> <p>There is no error but the activity doesn't show the values in the Listview but values can be seen using Toast.! <a href="http://i.stack.imgur.com/vQlWR.jpg" rel="nofollow">Output Of Activity using Toast</a></p> <h2><strong>here is my geo_ponts_list.xml file</strong></h2> <p> </p> <pre><code>&lt;TextView android:id="@+id/time" android:textSize="16sp" android:textStyle="bold" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@+id/latitude" android:textSize="16sp" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@+id/longitude" android:textSize="16sp" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt; </code></pre> <p></p> <hr>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload