Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListActivity row color based on object state
    primarykey
    data
    text
    <p>I have a ListActivity displaying a bunch of objects from a list. I want to change the background &amp; text color of the row based on the state of the two booleans in the MonitorObject.</p> <p>Do I need to extend ArrayAdapter? If so, a code sample would be greatly appreciated as I have been trying to figure it out for a few days with no success. </p> <pre><code>public class Lwm extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); setListAdapter(new ArrayAdapter&lt;MonitorObject&gt;(this, R.layout.row, getMonitorObjects())); } private List&lt;MonitorObject&gt; getMonitorObjects() { List&lt;MonitorObject&gt; mos = new ArrayList&lt;MonitorObject&gt;(); mos.add(new MonitorObject(15000, 20000, 25000)); mos.add(new MonitorObject(15000, 14000, 18000)); mos.add(new MonitorObject(15000, 12000, 14000)); mos.add(new MonitorObject(100, 200, 250)); mos.add(new MonitorObject(3000, 2500, 3500)); return mos; } } </code></pre> <hr> <pre><code>public class MonitorObject { private int mTimeTotal; private int mWarningThreshold; private int mAlarmThreshold;`enter code here` private boolean mWarning; private boolean mAlarm; public MonitorObject(int timeTotal, int warningThreshold, int alarmThreshold) { this.mTimeTotal = timeTotal; this.mWarningThreshold = warningThreshold; this.mAlarmThreshold = alarmThreshold; mWarning = (mTimeTotal &gt; mWarningThreshold) ? true : false; mAlarm = (mTimeTotal &gt; mAlarmThreshold) ? true : false; } /*getters, setters, tostring goes here*/ } </code></pre>
    singulars
    1. This table or related slice is empty.
    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