List of usage examples for android.util SparseBooleanArray size
public int size()
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 ww 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.potterpcs.recipebook.ImporterActivity.java
public void onImportButton(View v) { // We can't simply use getCheckedItemIds(), because it only works // if the ListAdapter has stable IDs, and ArrayAdapters don't. // So, we have to use getCheckedItemPositions instead, and loop // through the array. SparseBooleanArray sba = getListView().getCheckedItemPositions(); ArrayList<Recipe> selectedRecipes = new ArrayList<Recipe>(); for (int i = 0; i < sba.size(); i++) { if (sba.get(i)) { selectedRecipes.add(importedRecipes.get(i)); }/*from w ww. j a v a2 s . c o m*/ } data.insertImportedRecipes(selectedRecipes); finish(); }
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 w w w.j av a 2 s.c o m ((AvailableForm) listView.getItemAtPosition(checkedItemPositions.keyAt(i))).getFormUuid()); } } return formUUIDs; }
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 va 2 s . com*/ } 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:android.databinding.ViewDataBinding.java
/** @hide */ protected static void setTo(SparseBooleanArray list, int index, boolean value) { if (list == null || index < 0 || index >= list.size()) { return;// w w w .j a v a 2 s.c o m } list.put(index, value); }
From source file:com.akalipetis.action_mode_list_fragment.ActionModeListFragment.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public int calculateCheckedItems() { ListView l = getListView();/*from w ww. ja v a 2s .co m*/ if (Build.VERSION.SDK_INT >= 11) return l.getCheckedItemCount(); SparseBooleanArray checkedItems = l.getCheckedItemPositions(); if (checkedItems == null) return 0; int cnt = 0; for (int i = 0, lim = checkedItems.size(); i < lim; ++i) { int key = checkedItems.keyAt(i); if (checkedItems.get(key, false)) cnt++; } return cnt; }
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 . j a v a 2s .c o m 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:org.totschnig.myexpenses.dialog.SelectFromMappedTableDialogFragment.java
@Override public void onClick(DialogInterface dialog, int which) { if (getActivity() == null || mCursor == null) { return;//from www . j a v a 2 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:com.akalipetis.fragment.ActionModeListFragment.java
public int calculateCheckedItems() { ListView l = getListView();//w w w . j ava2s .co m if (Build.VERSION.SDK_INT >= 11) return l.getCheckedItemCount(); SparseBooleanArray checkedItems = l.getCheckedItemPositions(); if (checkedItems == null) return 0; int cnt = 0; for (int i = 0, lim = checkedItems.size(); i < lim; ++i) { int key = checkedItems.keyAt(i); if (checkedItems.get(key, false)) cnt++; } return cnt; }
From source file:net.seedboxer.seedroid.activities.fragments.DownloadsFragment.java
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Notice how the ListView api is lame // You can use mListView.getCheckedItemIds() if the adapter // has stable ids, e.g you're using a CursorAdaptor SparseBooleanArray checked = getListView().getCheckedItemPositions(); boolean hasCheckedElement = false; for (int i = 0; i < checked.size() && !hasCheckedElement; i++) { hasCheckedElement = checked.valueAt(i); }/*ww w. j a va 2s.c o m*/ if (hasCheckedElement) { if (mActionMode == null) { mActionMode = getView().startActionMode(new ModeCallback()); } } else { if (mActionMode != null) { mActionMode.finish(); } } }