Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList of Hashmaps not showing in Android listview
    primarykey
    data
    text
    <p>I am trying to populate a listview with an arraylist of Hashmaps (String, Integer). I'm not getting have any errors however the list does not show anything. I have looked at other questions similar to this but in those cases they did not have any data in their arraylists. From the logcat i can see the list is present but the view isn't showing. Any idea how to resolve this?</p> <p>CODE :</p> <pre><code>public class JsonActivity extends ListActivity{ private ProgressDialog progressDialog; // JSON Node names private static final String TAG_ID = "id"; private static final String TAG_ARTISTNAME = "artistname"; // chartItemList is the array list that holds the chart items ArrayList&lt;HashMap&lt;String, Integer&gt;&gt; chartItemList = new ArrayList&lt;HashMap&lt;String, Integer&gt;&gt;(); JsonParser Parser = new JsonParser(); // JSONArray JSONArray chartItems = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.progressdialog); //url from where the JSON has to be retrieved String url = "http://web.com/test.php"; //Check if the user has a connection ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) { if (!info.isConnected()) { Toast.makeText(this, "Please check your connection and try again.", Toast.LENGTH_SHORT).show(); } //if positive, fetch the articles in background else new getChartItems().execute(url); } //else show toast else { Toast.makeText(this, "Please check your connection and try again.", Toast.LENGTH_SHORT).show(); } } class getChartItems extends AsyncTask&lt;String, String, String&gt; { // Shows a progress dialog while executing background task @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(JsonActivity.this); progressDialog.setMessage("Loading chart..."); progressDialog.setIndeterminate(false); progressDialog.setCancelable(false); progressDialog.show(); } //Gets the json data for chart items data and presents it in a list view @Override protected String doInBackground(String... args) { String url = "http://web.com/test.php"; String json = Parser.getJSONFromUrl(url); int id; String artistname; try{ chartItems = new JSONArray(json); JSONObject json_data=null; for(int i=0;i&lt;chartItems.length();i++){ json_data = chartItems.getJSONObject(i); artistname=json_data.getString("artistname"); id=json_data.getInt("id"); HashMap&lt;String, Integer&gt; hashMap = new HashMap&lt;String, Integer&gt;(); // adding each child node to HashMap key =&gt; value hashMap.put(artistname,id); // adding HashMap to ArrayList chartItemList.add(hashMap); } ; } catch (JSONException e) { e.printStackTrace(); } runOnUiThread(new Runnable() { public void run() { System.out.println(chartItemList); //updating list view with the parsed items ListAdapter adapter = new SimpleAdapter(JsonActivity.this, chartItemList, R.layout.listview, new String[] {TAG_ARTISTNAME,TAG_ID }, new int[] {R.id.artistname,R.id.id }); setListAdapter(adapter); } }); return null; } //Removes the progress dialog when the data has been fetched protected void onPostExecute(String args) { progressDialog.dismiss(); } } } </code></pre> <p>VIEW :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="#eee"&gt; &lt;!-- Name Label --&gt; &lt;TextView android:id="@+id/id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#ff0a0a" android:textSize="16sp" android:textStyle="bold" android:paddingTop="6dip" android:paddingBottom="2dip" /&gt; &lt;TextView android:id="@+id/artistname" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000" android:textSize="10sp" android:paddingTop="6dip" android:paddingBottom="2dip" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    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.
    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