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

The following examples show how to use android.widget.ListView#getCheckedItemPositions() . 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 File: SelectPopupDialog.java    From 365browser with 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
Source File: BaseConfigureChildFragment.java    From Storm with Apache License 2.0 6 votes vote down vote up
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
Source File: SelectPopupDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: SelectPopupDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: InternalApisFragment.java    From line-sdk-android with Apache License 2.0 5 votes vote down vote up
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
Source File: MainActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
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)));
        }
    }
}