Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that your <code>getView()</code> method doesn't deal properly with views. You have to setup the state of new views and update the state of recycled views. In addition you have to define the behavior of the views. There are a lot of threads on SO with similar problems. I think <a href="https://stackoverflow.com/questions/11832907/gridview-with-custom-imageadapter-doesnt-update-after-dataset-changes">this one</a> can help you (it contains working code).</p> <p>Your code should look like the following skeleton:</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView; final int as=position; if (convertView == null) { // no view passed, create one LayoutInflater inflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); vi = inflater.inflate(R.layout.grid_item, null); // Setup the View content holder = new ViewHolder(); holder.textheader = (TextView) vi.findViewById(R.id.item1); holder.textcpu = (TextView) vi.findViewById(R.id.item2); holder.text_modified_date = (TextView) vi.findViewById(R.id.item4); holder.text_cpu = (TextView) vi.findViewById(R.id.item3); holder.text_checkbox=(CheckBox)vi.findViewById(R.id.checkBox1); // Do your checkbox initial setup here. holder.text_checkbox.setChecked(getBooleanFromPosition(position)); vi.setTag(holder); // Setup the View behavior holder.text_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { // Do your stuff here }); } else { // Update your View state holder = (ViewHolder) vi.getTag(); holder.text_checkbox.setChecked(getBooleanFromPosition(position)); } </code></pre> <p>Obviously you have to store the state of your checkboxes in some data structure, for instance a boolean array and read that data structure in order to know if the checkbox of a given position is checked/unchecked (that read access is what the <code>getBooleanFromPosition</code> is supposed to do). And that data structure should be updated in the section that controls the <code>View</code> behavior.</p>
 

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