Clear all selected items in a gridview

I have a gridview inside a ExpandableListView with CHOICE_MODE_MULTIPLE, I'm trying to deselect all items when I press a button, but the way I'm doing it it is only unselecting the last item, how can I clear all of them?

@Override public int getCount() { return child.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int arg0) { return 0; } @Override public View getView(final int position, View convertView, ViewGroup parent) { holder = null; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.child_item, null); holder = new ViewHolder(); holder.text = (TextView) convertView.findViewById(; convertView.setTag(holder); final View finalConvertView = convertView; convertView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { isChecked = child.get(position).isChecked(); if (!isChecked) { child.get(position).setChecked(true); } else { child.get(position).setChecked(false); } ex.findViewById( View.OnClickListener() { @Override public void onClick(final View v) { //clear all selected items for(int i = 0; i< getCount(); i++){ child.get(i).setChecked(false); } } }); } else { holder = (ViewHolder) convertView.getTag(); } holder.text.setText(child.get(position).getNome()); return convertView; } } } static class ViewHolder { TextView text; }

-------------Problems Reply------------

Try calling listView.clearChoices(); and adapter.notifyDataSetChanged(); from the activity or fragment containing the list, not inside the adapter.

Your problem is using calling child.size first, it is returning 1.
You are getting the child count from a different view.

public int getCount() {
return child.size();

If you call child.size() within you OnClickListener where you are using the

public void onClick(final View v) {

You should be iterating through the array adapter of the list, as the child.counts of the view will be different from the number of checked list items, if the list is scrollable. As there will be less items in the view (they are recycled) than within the list.

Category:java Views:3 Time:2019-01-05

Related post

  • How to clear all selected items in a SELECT input using jQuery? 2011-01-20

    I am think this should be fairly easy, but struggling a bit ... I have a SELECT input element that allows the user to select multiple items. I would like to provide a mechanism for them to clear all selected items, probably will just be a SPAN tag or

  • How to clear all selections in a wxListBox (with wxLB_MULTIPLE)? 2012-02-10

    How can I clear all selections in a wxListBox which has the style wxLB_MULTIPLE? Neither wxControlWithItems::SetSelection() nor wxControlWIthItems::SetStringSelection() work. They only select the passed item but they do not deselect any other items a

  • Quick way to clear all selections on a multiselect enabled with jQuery? 2010-02-12

    Do I have to iterate through ALL the and set remove the 'selected' attribute or is there a better way? --------------Solutions------------- Simply find all the selected <option> tags within your <select> and remove the selected attribute:

  • How to make a comboboxed silverlight control which would display in all selected items on the top? 2011-01-28

    I would like to ask, how to make a comboboxed silverlight control which would display in all selected items on the top ? Wtha what I have allready made is a combobox with checkboxes and a specific select logic. That is working fine. But one of the bu

  • DBLookupComboBox - How to clear the selected item? 2012-01-05

    What I tried to achieve is like setting ItemIndex to -1 as like in normal ComboBox, so that the selected item will be cleared. There is no ItemIndex for DBLookupComboBox, and the Text property is read only. So how do I clear the selected item? Please

  • how to clear all the items and add new item in the checkboxlist using javascript 2012-02-01

    I have one checkbox list like <asp:CheckBoxList id="CheckBoxList1" runat="server" > <asp:listitem Value="1">Item 1</asp:listitem> <asp:listitem Value="2">Item 2</asp:listitem> </asp:CheckBoxList>`. I need to clear

  • How to clear all the items of Jump List of a particular application with a single click? 2014-08-17

    Its very painful to remove contents of a jump list, specially when i wanna remove them all. I wanna know How to clear all the items of Jump List of a particular application with a single click? Is there any jump list manager available? or if you can

  • can i clear all deleeted items 2014-08-23

    how can i find a way to clean up my computer to clear all deleeted items thats slowing down the computer --------------Solutions------------- How is this affected by Internet Explorer? What deleted items? How are they slowing down the computer? Are t

  • How to deselect all selected items in a WPF treeview when clicking on some empty area? 2009-01-29

    I've got a rather funny problem with WPF. I have a tree-view, and selecting items works fine so far. The problem is, I want to unselect the currently selected item when the user clicks inside the blank area of the treeview. By default, the treeview k

  • ListBox not getting all selected items 2012-02-09

    I have a ListBox which is populated dynamically from a database in the code behind. I have another button and when i click the button, the button click event will get the all the selected listitem and insert the list item text to the database. I set

  • Get all selected items from ListBox 2009-12-02

    Anyone know of a smooth way to get all of the selected items in a listbox control by using extension methods? And, please, spare me the argument of it's irrelevant as to how one gets such a list because in the end everything uses a loop to iterate ov

  • How to clear all cached items in Oracle 2010-01-27

    I'm tuning SQL queries on an Oracle database. I want to ensure that all cached items are cleared before running each query in order to prevent misleading performance results. I clear out the shared pool (to get rid of cached SQL/explain plans) and bu

  • Using dropdownlist selected item to search gridview? 2011-05-18

    I've got a gridview that populates from four tables, and the select command (shown below) is fully functional. I'd like to be able to search the gridview, and display only those rows whose "Status" column value is equivalent to the selected item on a

  • How to clear all the items from a PropertyGrid 2012-01-16

    Is there a method that can clear the property grid of all its items? Or is there another way I can do this ? --------------Solutions------------- If we can assume that the object you are using to populate the PropertyGrid has "clear" default values,

  • Batch delete selected items on ListView/GridView 2014-05-17

    Following the guide found here I went up to a dead end on how to remove all the selected items from the listView's adapter. In the guide it is shown as a method called deleteSelectedItems();

  • Edit all selected items into one editor 2011-03-01

    Using QTableView I would like to be able to select multiple cells and change all selected cells at once. How I can do it? --------------Solutions------------- I'm not sure exactly what you mean by "changing" the selected cells (content, formatting, s

  • Clearing a selected item from a dropdown using PHP 2011-03-04

    I used the code below to remove a selected item from drop down, but when I remove one, the other item pops up. For example, if these are my options: "guns, cars, money", as I select and delete guns, cars and money remains. However, if I select cars a

  • Clearing all cached items created by a WebView? 2011-07-01

    I've got a WebView in my app. When the user logs out of my app, I'd like to delete all cached resources the WebView may have created. Looking at an emulator, I see the following files: /data /data /com.example.myapp /cache /webviewCache bunch of file

  • Check all checkbox and store all selected items in a global variable 2012-03-08

    I have a list of emails with a checkbox next to it, the user will be able to select which address he/she wants to email. Now i've added another checkbox that when checked will check all the other checkbox. Below is the code i wrote (with help from st

  • WPF DataGrid: modify all selected items 2010-09-10

    I want to take all rows that are selected and modify one column value in each of them. I tried this but it doesn't work. foreach (System.Data.DataRowView DRV in ItemDataGrid.SelectedItems) { DRV.Row.BeginEdit(); DRV.Row.ItemArray[6] = true; DRV.Row.E

  • Need to access image for selected item in android gridview 2011-02-16

    I want to access the properties of an image when it is selected from a gridview. For example if I am using. GridView gridview = (GridView) findViewById(; gridview.setAdapter(new ImageAdapter(this)); gridview.setOnItemClickListener(n

  • Remove all selected items from multiple selects using asmselect 2011-08-13

    I have multiple asmselect 'select multiple' form inputs on a page I'm developing. I'd like a 'clear' button that resets these to their initial, nothing selected state. I've tried variations of: $('.asmSelect option[selected]').removeAttr("selected");

  • Get all selected items in a TreeStore 2012-04-02

    I have a TreeStore that you can drill into. It's only two levels deep. When you get to the second level and you click on a leaf it takes you to a detail card. How do I, in the detail card, show the full path? So say I have; - A - 1 - 2 - B - 1 - 3 -

  • Cloning a div resets all selected items of the destination div 2012-04-13

    The problem I have : I click "add" I select 2nd option I click "add" Problem : my first select-list's selected option index = 0; This should not happen, but I can't figure out why it does it anyway. Can anyone tell me what I did wrong? <script typ

  • Save selected items when using caliburn.micro /Telerik RadGridView /Silverlight 2012-01-27

    I am using Caliburn micro(1.3)/MVVM and Silverlight. When I update the itemsource RadGridView, I lose the selected items. I found a blog about implementing a behavior to save the selected items when you are implementing MVVM. I can get the selected i

Copyright (C), All Rights Reserved.

processed in 0.091 (s). 11 q(s)