Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <code>ListView</code> is just a presentation of data. The data is given to the <code>ListView</code> by an <code>Adapter</code>. This being said, I can explain what you did wrong:</p> <p>Inside your <code>OnClickListener</code>, you are (un)checking a <code>View</code> of the <code>ListView</code> itself. This means the data is not being changed and the <code>ListView</code> which represents this data, does not display the wanted behavior.</p> <p>A simple solution would be adding a boolean to your <code>Model</code>-object which indicates the checked-state:</p> <pre><code>Model { boolean isChecked = false; public void setChecked(boolean checked){ isChecked = checked; } public boolean isChecked(){ return isChecked; } } </code></pre> <p>Whenever you click the 'selectall'-button, you will simple toggle this boolean and notify the <code>Adapter</code> that his data has changed with the method <code>notifyDataSetChanged</code>. This will on his turn update the <code>ListView</code> itself. In pseudocode:</p> <pre><code> onClick(..) { foreach (model inside my adapter){ model.setChecked(true); } listview.getAdapter().notifyDataSetChanged() } </code></pre> <p>Last but not least, in the <code>getView()</code>-method inside your <code>Adapter</code> you can see if a <code>Model</code> is checked or not and act accordingly. </p> <pre><code>getView(...){ if (listOfModel.get(position).isChecked){ // do stuff, probably check a CheckBox } else { // uncheck... } </code></pre> <p>Good luck!</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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