Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the similar issue with my <code>ListView</code> with <code>CheckBox</code> and what I did to get rid of the problem:</p> <ul> <li>Create an ArrayList of Boolean Object to store the state of the each CheckBox</li> <li>Initializes the ArrayList items to default value <code>false</code>, means no CheckBox is checked yet.</li> <li>When you click on CheckBox. Set a check against Checked/Unchecked state and store that value in ArrayList.</li> <li>Now set that position to CheckBox using setChecked() method.</li> </ul> <h2>See this code snippet:</h2> <pre><code>public class MyDataAdapter extends SimpleCursorAdapter { private Cursor c; private Context context; private ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;(); private ArrayList&lt;Boolean&gt; itemChecked = new ArrayList&lt;Boolean&gt;(); // itemChecked will store the position of the checked items. public MyDataAdapter(Context context, int layout, Cursor c, String[] from, int[] to) { super(context, layout, c, from, to); this.c = c; this.context = context; for (int i = 0; i &lt; this.getCount(); i++) { itemChecked.add(i, false); // initializes all items value with false } } public View getView(final int pos, View inView, ViewGroup parent) { if (inView == null) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); inView = inflater.inflate(R.layout.your_layout_file, null); } final CheckBox cBox = (CheckBox) inView.findViewById(R.id.bcheck); // your // CheckBox cBox.setOnClickListener(new OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v.findViewById(R.id.your_checkbox_id); if (cb.isChecked()) { itemChecked.set(pos, true); // do some operations here } else if (!cb.isChecked()) { itemChecked.set(pos, false); // do some operations here } } }); cBox.setChecked(itemChecked.get(pos)); // this will Check or Uncheck the // CheckBox in ListView // according to their original // position and CheckBox never // loss his State when you // Scroll the List Items. return inView; }} </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.
    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.
    3. 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