Note that there are some explanatory texts on larger screens.

plurals
  1. POManipulate a row from a ListView populated by SimpleAdapter
    text
    copied!<p>Im populating a ListView using the following:</p> <pre class="lang-java prettyprint-override"><code>list = (ListView) findViewById(R.id.historylist); ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); String[] titles = new String[]{"transactionID","date","description","redeem","reward","status"}; try{ for(int i=0;i&lt;rows.length();i++){ map = new HashMap&lt;String, String&gt;(); for(int n=0;n&lt;allRows.getJSONArray(i).length();n++){ map.put(titles[n], allRows.getJSONArray(i).getString(n)); } mylist.add(map); } mSchedule = new SimpleAdapter( History.this, mylist, R.layout.history_row, titles, new int[] {R.id.textView0, R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5}); list.setAdapter(mSchedule); for(int i=0; i&lt;mylist.size(); i++) if(((Map&lt;String, String&gt;) mSchedule.getItem(i)).get("status").equals("0")) try{ // SET BACKGROUND COLOR OF ROW }catch(Exception e){ Log.e("AAA Error getting ListView row", e.toString()); } }catch(Exception e){ Log.e("Error Creating ListView", e.toString()); } </code></pre> <p>I'd like to change the background color of any ListView row which contains a status of "0".</p> <p>Any ideas?</p> <p><strong>NEW: Here's the updated code - much nicer (Except for the part where I have to manually chop characters from the JSONArray.. eww..)</strong></p> <pre class="lang-java prettyprint-override"><code>private void showListView(JSONArray rows, JSONArray totals){ list = (ListView) findViewById(android.R.id.list); ArrayList&lt;String[]&gt; rowValues = null; String[] r = null; try{ rowValues = new ArrayList&lt;String[]&gt;(); for (int i=0;i&lt;rows.length();i++){ r = rows.get(i).toString().replaceAll("\\[\"", "").replaceAll("\"\\]", "").split("\",\""); rowValues.add(r); } mba = new MyBaseAdapter(this, rowValues); list.setAdapter(mba); }catch(Exception e){ Log.e("showListView() ERROR", e.toString()); } } </code></pre>
 

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