Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This will get all the views in your listview and will get the checkbox in each view and sets them to be checked:</p> <pre><code>List&lt;View&gt; listOfViews = new ArrayList&lt;View&gt;(); listView1.reclaimViews(listOfViews); for (View v : listOfViews) { CheckBox cb = (CheckBox)v.findViewById(R.id.checkbox); cb.setChecked(true); } </code></pre> <p><strong>UPDATE:</strong></p> <p>Before initializing the adapter, create an arraylist that contains the checkstates of all the checkboxes. Then pass this arraylist as an argument to your custom adapter and use in the getView() function (checkStates is the arraylist in the below code):</p> <pre><code> public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; ViewHolder holder; if(convertView==null){ vi = inflater.inflate(R.layout.item, null); holder=new ViewHolder(); holder.text=(TextView)vi.findViewById(R.id.text);; holder.image=(ImageView)vi.findViewById(R.id.image); CheckBox checkbox = (CheckBox)vi.findViewById(R.id.chkbox); checkbox.setChecked(checkStates.get(position); holder.ck= checkbox; vi.setTag(holder); } else holder=(ViewHolder)vi.getTag(); holder.text.setText(nume[position]); holder.image.setTag(data[position]); holder.ck.setChecked(checkStates.get(position)); imageLoader.DisplayImage(data[position], activity, holder.image); return vi; } </code></pre> <p>Then when you want to check all the checkboxes, set all the values in the arraylist containing the checkstates of the checkboxes as true. Then call <code>listView1.setAdapter(adapter);</code></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