Example usage for android.util SparseBooleanArray keyAt

List of usage examples for android.util SparseBooleanArray keyAt

Introduction

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

Prototype

public int keyAt(int index) 

Source Link

Document

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

Usage

From source file:com.pentapus.pentapusdmh.Fragments.EncounterPrep.AddMonster.WizardMonsterEdit.DmgVulFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    if (selections != null) {
        selections = new ArrayList<String>();
    }//from   ww  w .jav a2s. co  m
    for (int i = 0; i < checkedPositions.size(); i++) {
        if (checkedPositions.valueAt(i)) {
            selections.add(getListAdapter().getItem(checkedPositions.keyAt(i)).toString());
        }
    }

    mPage.getData().putStringArrayList(Page.SIMPLE_DATA_KEY, selections);
    mPage.notifyDataChanged();
}

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);
        }/* w w  w.ja va 2s  . c om*/

    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: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 v a  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: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);
        }/*from w  ww .j av  a 2s  . c  o m*/
    }
}

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

@Override
public void onClick(DialogInterface dialog, int which) {
    if (getActivity() == null || mCursor == null) {
        return;// w ww . j  a  v  a2  s.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: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  w w w.j a v  a2s  .  co  m*/
    }
    return -1;
}

From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java

private void deleteItems(SparseBooleanArray positions) {

    SparseBooleanArray chkItems = positions;
    //ArrayList<Game> selItems = new ArrayList<Game>();
    ArrayList<Long> selItems = new ArrayList<Long>();
    for (int i = 0; i < chkItems.size(); i++) {
        int position = chkItems.keyAt(i);
        if (chkItems.valueAt(i)) {
            selItems.add(adapter.getItem(position).getId());
        }/*from   www . j a  v a 2 s . co  m*/
    }
    DeleteGameTask task = new DeleteGameTask();
    Long[] longs = new Long[selItems.size()];
    longs = selItems.toArray(longs);
    task.execute(longs);

    /*
            for(Game g:selItems) {
    dataSource.deleteGame(g);
    mListener.onMultipleItemsDeletion();
    //dataSource.deleteSchedule(context, s);
    //updateDB();
            }*/
}

From source file:com.miz.mizuu.UnidentifiedFiles.java

private void identifySelectedFiles() {
    SparseBooleanArray sba = mList.getCheckedItemPositions();
    ArrayList<String> filepaths = new ArrayList<String>(), rowIds = new ArrayList<String>();
    for (int i = 0; i < sba.size(); i++) {
        filepaths.add(episodes.get(sba.keyAt(i)).getFullFilepath());
        rowIds.add(episodes.get(sba.keyAt(i)).getRowId());
    }//from   www .  j av  a  2 s  .  c  o  m

    Intent i = new Intent();
    i.setClass(this, IdentifyTvShow.class);
    i.putExtra("rowIds", rowIds.toArray(new String[rowIds.size()]));
    i.putExtra("rowId", "0");
    i.putExtra("files", filepaths.toArray(new String[filepaths.size()]));
    i.putExtra("showName", "");
    i.putExtra("oldShowId", "0");
    i.putExtra("includeShowData", true);
    startActivity(i);
}

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(//w w w.j  ava  2s  . c om
                    ((AvailableForm) listView.getItemAtPosition(checkedItemPositions.keyAt(i))).getFormUuid());
        }
    }
    return formUUIDs;
}

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  ww.  j  a  va2 s  .  co m*/

    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;
}