List of usage examples for android.util SparseBooleanArray keyAt
public int keyAt(int index)
0...size()-1
, returns the key from the index
th key-value mapping that this SparseBooleanArray stores. From source file:org.kontalk.util.SystemUtils.java
/** * Provides clone functionality for the {@link SparseBooleanArray}. * See https://code.google.com/p/android/issues/detail?id=39242 *//*from w w w. ja v a 2 s .co m*/ public static SparseBooleanArray cloneSparseBooleanArray(SparseBooleanArray array) { final SparseBooleanArray clone = new SparseBooleanArray(); synchronized (array) { final int size = array.size(); for (int i = 0; i < size; i++) { int key = array.keyAt(i); clone.put(key, array.get(key)); } } return clone; }
From source file:nl.mpcjanssen.simpletask.util.Util.java
public static ArrayList<String> getCheckedItems(ListView listView, boolean checked) { SparseBooleanArray checks = listView.getCheckedItemPositions(); ArrayList<String> items = new ArrayList<String>(); for (int i = 0; i < checks.size(); i++) { String item = (String) listView.getAdapter().getItem(checks.keyAt(i)); if (checks.valueAt(i) && checked) { items.add(item);/*from w ww . j av a2 s.co m*/ } else if (!checks.valueAt(i) && !checked) { items.add(item); } } return items; }
From source file:com.andremion.louvre.sample.MediaTypeFilterDialog.java
@NonNull private String[] parseToArray(@NonNull SparseBooleanArray selectedTypes) { List<String> selectedTypeList = new ArrayList<>(); for (int i = 0; i < selectedTypes.size(); i++) { int key = selectedTypes.keyAt(i); if (selectedTypes.get(key, false)) { selectedTypeList.add(Louvre.IMAGE_TYPES[key]); }/* w w w . j av a 2 s .com*/ } String[] array = new String[selectedTypeList.size()]; selectedTypeList.toArray(array); return array; }
From source file:ca.rmen.android.networkmonitor.app.prefs.SelectFieldsActivity.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { Log.v(TAG, "onListItemClick: clicked on view " + v + " at position " + position + " with id " + id); View okButton = findViewById(R.id.ok); SparseBooleanArray checkedItemPositions = l.getCheckedItemPositions(); for (int i = 0; i < checkedItemPositions.size(); i++) { if (checkedItemPositions.get(checkedItemPositions.keyAt(i))) { okButton.setEnabled(true);/*from ww w . ja v a 2 s . c om*/ return; } } okButton.setEnabled(false); }
From source file:ch.hesso.master.sweetcity.activity.tag.TagSelectionActivity.java
@Override public void onClick(View v) { SparseBooleanArray checked = listView.getCheckedItemPositions(); ArrayList<Integer> selectedItems = new ArrayList<Integer>(); for (int i = 0; i < checked.size(); i++) { int position = checked.keyAt(i); if (checked.valueAt(i)) { selectedItems.add(CurrentTagList.getInstance().getPosition(adapter.getItem(position))); }//from w w w . ja v a2 s . com } // Return tag selection list to the parent activity Intent resultIntent = new Intent(); Bundle bundle = new Bundle(); bundle.putIntegerArrayList("selectedItems", selectedItems); resultIntent.putExtras(bundle); setResult(Activity.RESULT_OK, resultIntent); finish(); }
From source file:org.akop.crosswords.fragment.BaseFragment.java
protected void putSparseBooleanArray(Bundle bundle, String prefix, SparseBooleanArray array) { int size = array.size(); int keys[] = new int[size]; boolean values[] = new boolean[size]; for (int i = 0; i < size; i++) { keys[i] = array.keyAt(i); values[i] = array.valueAt(i);/*from w ww .ja v a 2 s . c o m*/ } bundle.putIntArray(prefix + "_keys", keys); bundle.putBooleanArray(prefix + "_values", values); }
From source file:com.connectsdk.smarthomesampler.fragment.SetupMultiChoiceFragment.java
@OnClick(R.id.btnNext) public void onNextStep() { SparseBooleanArray checked = listView.getCheckedItemPositions(); ids.clear();/*ww w . j ava 2 s. c o m*/ if (adapter != null) { for (int i = 0; i < checked.size(); i++) { if (checked.get(checked.keyAt(i))) { T device = adapter.getItem(checked.keyAt(i)); ids.add(getDeviceId(device)); } } } save(); }
From source file:de.vanita5.twittnuker.popup.AccountSelectorPopupWindow.java
@NonNull public long[] getSelectedAccountIds() { final long[] accountIds = new long[mGridView.getCheckedItemCount()]; final SparseBooleanArray positions = mGridView.getCheckedItemPositions(); for (int i = 0, j = positions.size(), k = 0; i < j; i++) { if (positions.valueAt(i)) { accountIds[k++] = mAdapter.getItem(positions.keyAt(i)).account_id; }/* www .jav a 2 s . c om*/ } return accountIds; }
From source file:com.test.weeklly.gplus.ListPeopleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.person_list_activity); mListItems = new ArrayList<String>(); mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, mListItems);/*from w w w. ja v a 2 s .c o m*/ mPersonListView = (ListView) findViewById(R.id.person_list); mPersonListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); mPersonListView.setAdapter(mListAdapter); mPlusClientFragment = PlusClientFragment.getPlusClientFragment(this, MomentUtil.VISIBLE_ACTIVITIES); done = (Button) findViewById(R.id.done); done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String str = ""; SparseBooleanArray checked = mPersonListView.getCheckedItemPositions(); int size = checked.size(); // number of name-value pairs in the array for (int i = 0; i < size; i++) { int key = checked.keyAt(i); boolean value = checked.get(key); if (value) { str += "\n" + mListItems.get(key); done.setText(str); Intent returnIntent = new Intent(); returnIntent.putExtra("result", str); setResult(RESULT_OK, returnIntent); finish(); } //doSomethingWithSelectedIndex(key); } } }); }
From source file:com.btmura.android.reddit.app.SubredditActionModeController.java
@Override public boolean onPrepareActionMode(ActionMode mode, Menu menu, ListView lv) { int count = lv.getCheckedItemCount(); boolean aboutItemVisible = count == 1; boolean shareItemsVisible = count == 1; SparseBooleanArray checked = lv.getCheckedItemPositions(); int size = checked.size(); for (int i = 0; i < size; i++) { if (checked.valueAt(i)) { int position = checked.keyAt(i); String subreddit = adapter.getName(position); boolean hasSidebar = Subreddits.hasSidebar(subreddit); aboutItemVisible &= hasSidebar; shareItemsVisible &= hasSidebar; }/* www .j a v a2s . c o m*/ } prepareMode(count); prepareAddItem(menu); prepareAboutItem(menu, lv, aboutItemVisible); prepareDeleteItem(menu); prepareShareItems(menu, shareItemsVisible); return true; }