Note that there are some explanatory texts on larger screens.

plurals
  1. POListView item backgrounds not changing
    primarykey
    data
    text
    <p>I have an unusual issue with my <code>ListView</code>. I currently have a "<code>deselectAll()</code>" method which iterates through the items in my ListView and sets them to unchecked (the items implement the <code>Checkable</code> interface). The "checked" variable gets changed correctly (the view reports as not being checked), but the visual indicator (in this case, a background change) does not show the view as unchecked (the background stays the color of a checked item).</p> <p>I am iterating and deselecting through my listview like so (I also added my declerations):</p> <pre><code>private ListView vw_entryList; private void deselectAll() { for (int i = 0; i &lt; sAdapter.getCount(); i++) { ((Entry)vw_entryList.getItemAtPosition(i)).setChecked(false); } } </code></pre> <p>The code for my implemented <code>setChecked()</code> is as follows:</p> <pre><code>public void setChecked(boolean checked) { _checked = checked; if (checked) { setBackgroundResource(R.drawable.listview_checked); } else { setBackgroundResource(R.drawable.listview_unchecked); } invalidate(); } </code></pre> <p>It should be noted that when the items are clicked, they are toggled between checked and unchecked in the <code>OnItemClickListener</code>, and this works ok, with the background change and everything. The code for toggling is very similar:</p> <pre><code>public void toggle() { _checked = !_checked; setBackgroundResource(_checked ? R.drawable.listview_checked : R.drawable.listview_unchecked); invalidate(); } </code></pre> <p>The only difference I can see is where the methods are called from. <code>toggle()</code> is called from within the <code>OnItemClickListener.onClick()</code> method, while my <code>deselectAll()</code> is called from within a button's standard <code>OnClickListener</code>, both in the same class. <strong>Does anyone have any ideas as to why the background doesn't change when I call my deselectAll() function?</strong></p>
    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.
    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