Java Code Examples for android.widget.ListView#getCheckedItemPositions()

The following examples show how to use android.widget.ListView#getCheckedItemPositions() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: 365browser   File: SelectPopupDialog.java    License: Apache License 2.0 6 votes vote down vote up
private static int[] getSelectedIndices(ListView listView) {
    SparseBooleanArray sparseArray = listView.getCheckedItemPositions();
    int selectedCount = 0;
    for (int i = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            selectedCount++;
        }
    }
    int[] indices = new int[selectedCount];
    for (int i = 0, j = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            indices[j++] = sparseArray.keyAt(i);
        }
    }
    return indices;
}
 
Example 2
protected void processSelectedStates(ListView listView, ConfigureAdapterItem[] items) {
    final int choiceMode = listView.getChoiceMode();
    if (choiceMode == AbsListView.CHOICE_MODE_MULTIPLE) {
        final SparseBooleanArray array = listView.getCheckedItemPositions();
        int key;
        for (int i = 0; i < array.size(); i++) {
            key = array.keyAt(i);
            items[key].setChecked(array.valueAt(i));
        }
    } else if (choiceMode == AbsListView.CHOICE_MODE_SINGLE) {
        final int position = listView.getCheckedItemPosition();
        for (int i = 0; i < items.length; i++) {
            items[i].setChecked(i == position);
        }
    }
}
 
Example 3
private int[] getSelectedIndices(ListView listView) {
    SparseBooleanArray sparseArray = listView.getCheckedItemPositions();
    int selectedCount = 0;
    for (int i = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            selectedCount++;
        }
    }
    int[] indices = new int[selectedCount];
    for (int i = 0, j = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            indices[j++] = sparseArray.keyAt(i);
        }
    }
    return indices;
}
 
Example 4
private int[] getSelectedIndices(ListView listView) {
    SparseBooleanArray sparseArray = listView.getCheckedItemPositions();
    int selectedCount = 0;
    for (int i = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            selectedCount++;
        }
    }
    int[] indices = new int[selectedCount];
    for (int i = 0, j = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            indices[j++] = sparseArray.keyAt(i);
        }
    }
    return indices;
}
 
Example 5
private final List<String> getSelectedReceiverIDs(final ListView listView) {
    final List<String> receiverIDs = new ArrayList<>();

    final Adapter adapter = listView.getAdapter();
    final SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
    for (int i = 0; i < adapter.getCount(); i++) {
        if (checkedItems.get(i)) {
            receiverIDs.add(((Receiver) adapter.getItem(i)).id);
        }
    }

    return receiverIDs;
}
 
Example 6
private void deleteSelectedItems(){
    ListView notesList = (ListView) findViewById(R.id.notes_list);
    CursorAdapter adapter = (CursorAdapter) notesList.getAdapter();
    SparseBooleanArray checkedItemPositions = notesList.getCheckedItemPositions();
    for (int i=0; i < checkedItemPositions.size(); i++) {
        if(checkedItemPositions.valueAt(i)) {
            DbAccess.trashNote(getBaseContext(), (int) (long) adapter.getItemId(checkedItemPositions.keyAt(i)));
        }
    }
}