Example usage for android.util SparseBooleanArray valueAt

List of usage examples for android.util SparseBooleanArray valueAt

Introduction

In this page you can find the example usage for android.util SparseBooleanArray valueAt.

Prototype

public boolean valueAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the value from the indexth key-value mapping that this SparseBooleanArray stores.

Usage

From source file:org.totschnig.myexpenses.dialog.SelectFromTableDialogFragment.java

@Override
public void onClick(DialogInterface dialog, int which) {
    if (getActivity() == null || mCursor == null) {
        return;//from  w w w.j a v  a2s  .co  m
    }
    ListView listView = ((AlertDialog) dialog).getListView();
    SparseBooleanArray positions = listView.getCheckedItemPositions();

    long[] itemIds = listView.getCheckedItemIds();

    if (itemIds.length > 0) {
        ArrayList<String> labelList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            if (positions.valueAt(i)) {
                mCursor.moveToPosition(positions.keyAt(i));
                labelList.add(mCursor.getString(mCursor.getColumnIndex(getColumn())));
            }
        }
        onResult(labelList, itemIds);
    }
    dismiss();
}

From source file:com.muzima.view.cohort.FormTemplateWizardActivity.java

private List<String> getSelectedForms() {
    List<String> formUUIDs = new ArrayList<String>();
    SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i)) {
            formUUIDs.add(//from   ww  w.  j  a  va 2 s .c  om
                    ((AvailableForm) listView.getItemAtPosition(checkedItemPositions.keyAt(i))).getFormUuid());
        }
    }
    return formUUIDs;
}

From source file:org.totschnig.myexpenses.dialog.SelectFromMappedTableDialogFragment.java

@Override
public void onClick(DialogInterface dialog, int which) {
    if (getActivity() == null || mCursor == null) {
        return;//  w  w w.ja v  a  2s . c  o  m
    }
    ListView listView = ((AlertDialog) dialog).getListView();
    SparseBooleanArray positions = listView.getCheckedItemPositions();

    long[] itemIds = listView.getCheckedItemIds();

    if (itemIds.length > 0) {
        ArrayList<String> labelList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            if (positions.valueAt(i)) {
                mCursor.moveToPosition(positions.keyAt(i));
                labelList.add(mCursor.getString(mCursor.getColumnIndex(KEY_LABEL)));
            }
        }
        ((MyExpenses) getActivity()).addFilterCriteria(getCommand(),
                makeCriteria(TextUtils.join(",", labelList), itemIds));
    }
    dismiss();
}

From source file:at.bitfire.nophonespam.BlacklistActivity.java

protected void deleteSelectedNumbers() {
    final List<String> numbers = new LinkedList<>();

    SparseBooleanArray checked = list.getCheckedItemPositions();
    for (int i = checked.size() - 1; i >= 0; i--)
        if (checked.valueAt(i)) {
            int position = checked.keyAt(i);
            numbers.add(adapter.getItem(position).number);
        }//from  www.j  a va 2  s.  com

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            DbHelper dbHelper = new DbHelper(BlacklistActivity.this);
            try {
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                for (String number : numbers)
                    db.delete(Number._TABLE, Number.NUMBER + "=?", new String[] { number });
            } finally {
                dbHelper.close();
            }

            getLoaderManager().restartLoader(0, null, BlacklistActivity.this);
            return null;
        }
    }.execute();
}

From source file:net.naonedbus.fragment.impl.GroupesFragment.java

private void deleteCheckedItems() {
    final SparseBooleanArray checked = mListView.getCheckedItemPositions();
    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            final int position = checked.keyAt(i);
            final int idGroupe = (int) mListView.getItemIdAtPosition(position);
            mGroupeManager.delete(getActivity().getContentResolver(), idGroupe);
        }//w  w w .jav a2  s.  co  m
    }
}

From source file:com.btmura.android.reddit.app.SubredditActionModeController.java

private String[] getCheckedSubreddits(ListView lv) {
    SparseBooleanArray checked = lv.getCheckedItemPositions();
    String[] subreddits = new String[lv.getCheckedItemCount()];

    int size = checked.size();
    int j = 0;//from   w w  w  .  j  a  va 2  s . c o  m
    for (int i = 0; i < size; i++) {
        if (checked.valueAt(i)) {
            int position = checked.keyAt(i);
            subreddits[j++] = adapter.getName(position);
        }
    }

    return subreddits;
}

From source file:de.vanita5.twittnuker.fragment.support.DataExportImportTypeSelectorDialogFragment.java

private int getCheckedFlags() {
    final SparseBooleanArray checked = mListView.getCheckedItemPositions();
    int flags = 0;
    for (int i = 0, j = checked.size(); i < j; i++) {
        final Type type = (Type) mListView.getItemAtPosition(i);
        if (checked.valueAt(i)) {
            flags |= type.flag;//from   w w w. j  a va2  s  . co m
        }
    }
    return flags;
}

From source file:net.naonedbus.fragment.impl.GroupesFragment.java

private int getFirstSelectedItemPosition() {
    final SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    for (int i = 0; i < checkedPositions.size(); i++) {
        if (checkedPositions.valueAt(i)) {
            return checkedPositions.keyAt(i);
        }//from   ww w  .  ja va2  s . co m
    }
    return -1;
}

From source file:com.fusionx.lightirc.ui.UserListFragment.java

protected List<WorldUser> getCheckedItems() {
    final List<WorldUser> checkedSessionPositions = new ArrayList<>();
    if (mStickyListView == null) {
        return checkedSessionPositions;
    }/*from  w  w w.ja v a  2 s.  com*/

    final SparseBooleanArray checkedPositionsBool = mStickyListView.getCheckedItemPositions();
    for (int i = 0; i < checkedPositionsBool.size(); i++) {
        if (checkedPositionsBool.valueAt(i)) {
            checkedSessionPositions.add(mAdapter.getItem(checkedPositionsBool.keyAt(i)));
        }
    }

    return checkedSessionPositions;
}

From source file:com.muzima.view.cohort.FormTemplateWizardActivity.java

private boolean hasRegistrationFormSelected() {
    SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();
    boolean registrationFormSelected = false;
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i)) {
            AvailableForm selectedForm = (AvailableForm) listView
                    .getItemAtPosition(checkedItemPositions.keyAt(i));
            if (selectedForm.isRegistrationForm()) {
                registrationFormSelected = true;
            }//from  ww w .  j  ava2s  . c  o m
        }
    }
    return registrationFormSelected;
}