Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all items within ListView

I am currently working on an Android project. I am using a ListView and using a context action bar and I am successfully selecting each item and showing a count of how many items have been selected within the list view.

Within the context bar I have a menu option for Select All but I don't know how I can make sure that every item within the list view is selected.

I can't seem to find anything on Google, anything about this type of thing and selectable ListViews seem to be very well hidden.

like image 736
Boardy Avatar asked Jun 16 '12 16:06

Boardy


People also ask

How to select all items in ListView in android?

If you only want to select what is on screen, then use listview. getChildCount() . If you are using fragments, you will need to use getListAdapter(). getCount() .


1 Answers

You can check listview items one by one:

for ( int i=0; i < listview.getAdapter().getCount(); i++) {
   listview.setItemChecked(i, true);
}

If you only want to select what is on screen, then use listview.getChildCount().

If you are using fragments, you will need to use getListAdapter().getCount().

like image 184
matskiv Avatar answered Oct 07 '22 09:10

matskiv