List of usage examples for android.widget ListView getCheckedItemPositions
public SparseBooleanArray getCheckedItemPositions()
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; }//from w ww. j a va 2 s. co m } prepareMode(count); prepareAddItem(menu); prepareAboutItem(menu, lv, aboutItemVisible); prepareDeleteItem(menu); prepareShareItems(menu, shareItemsVisible); return true; }
From source file:com.btmura.android.reddit.app.CommentListController.java
private boolean isAllDeletable(ListView lv) { SparseBooleanArray checked = lv.getCheckedItemPositions(); int count = adapter.getCount(); for (int i = 0; i < count; i++) { if (checked.get(i) && (!isAuthor(i) || !hasThingId(i))) { return false; }/* w w w. ja va 2 s . com*/ } return true; }
From source file:com.btmura.android.reddit.app.CommentListController.java
public void delete(ListView lv) { SparseBooleanArray checkedItemPositions = lv.getCheckedItemPositions(); long[] checkedItemIds = lv.getCheckedItemIds(); String[] checkedThingIds = new String[checkedItemIds.length]; boolean[] hasChildren = new boolean[checkedItemIds.length]; fillCheckedInfo(checkedItemPositions, checkedThingIds, hasChildren); Provider.deleteCommentAsync(context, accountName, hasChildren, checkedItemIds, getThingId(0), checkedThingIds);/*from w ww.j a v a2 s . co m*/ }
From source file:com.tinfoil.sms.sms.KeyExchangeManager.java
/** * The onClick action for when a for when the reject button has been * clicked. Deletes every key exchange message selected. * @param view The View//w w w .j av a2 s. c o m */ public void reject(View view) { if (runThread.getEntries() != null) { ListView list = (ListView) this.findViewById(R.id.key_exchange_list); SparseBooleanArray sba = list.getCheckedItemPositions(); for (int i = 0; i < runThread.getEntries().size(); i++) { if (sba.get(i)) { dba.deleteKeyExchangeMessage(runThread.getEntries().get(i).getNumber()); runThread.getEntries().remove(runThread.getEntries().get(i)); } } //finish(); } updateList(); }
From source file:com.tinfoil.sms.sms.KeyExchangeManager.java
/** * The onClick action for when the exchange key message is pressed. Sends a * key exchange message for each contact that is selected. * @param view The View //www .j a va 2s .c om */ public void exchangeKey(View view) { if (runThread.getEntries() != null) { ListView list = (ListView) this.findViewById(R.id.key_exchange_list); SparseBooleanArray sba = list.getCheckedItemPositions(); int i = 0; while (runThread.getEntries() != null && i < runThread.getEntries().size()) { if (sba.get(i)) { TrustedContact tc = dba.getRow(SMSUtility.format(runThread.getEntries().get(0).getNumber())); final Number number = tc .getNumber(SMSUtility.format(runThread.getEntries().get(0).getNumber())); if (SMSUtility.checksharedSecret(number.getSharedInfo1()) && SMSUtility.checksharedSecret(number.getSharedInfo2())) { respondKeyExchangeMessage(this, number, runThread.getEntries().get(i)); } else { requestSharedSecrets(this, number, tc.getName(), runThread.getEntries().get(i)); } } i++; } } }
From source file:com.btmura.android.reddit.app.NavigationFragment.java
private String[] getCheckedSubreddits() { ListView lv = getListView(); SparseBooleanArray checked = lv.getCheckedItemPositions(); String[] subreddits = new String[lv.getCheckedItemCount()]; int size = checked.size(); int j = 0;// ww w . j a v a 2 s . co m for (int i = 0; i < size; i++) { if (checked.valueAt(i)) { int position = checked.keyAt(i); int adapterPosition = mergeAdapter.getAdapterPosition(position); subreddits[j++] = subredditAdapter.getName(adapterPosition); } } return subreddits; }
From source file:com.Candy.sizer.CandySizer.java
private void showDialog(int id, final String item, final ArrayAdapter<String> adapter, int itemCounter) { // startup dialog final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); if (id == STARTUP_DIALOG) { // create warning dialog alert.setMessage(R.string.sizer_message_startup).setTitle(R.string.caution).setCancelable(true) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for ok dialog.cancel(); }/*from w ww . j a v a2 s. c o m*/ }); // delete dialog } else if (id == DELETE_DIALOG) { alert.setMessage(R.string.sizer_message_delete) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for ok // call delete new CandySizer.SlimDeleter().execute(item); // remove list entry adapter.remove(item); adapter.notifyDataSetChanged(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for cancel dialog.cancel(); } }); } else if (id == DELETE_MULTIPLE_DIALOG) { String message; if (itemCounter == 1) { message = getResources().getString(R.string.sizer_message_delete_multi_one); } else { message = getResources().getString(R.string.sizer_message_delete_multi); } alert.setMessage(message).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { final ListView lv = (ListView) getView().findViewById(R.string.listsystem); ArrayList<String> itemsList = new ArrayList<String>(); SparseBooleanArray checked = lv.getCheckedItemPositions(); for (int i = lv.getCount() - 1; i > 0; i--) { if (checked.get(i)) { String appName = mSysApp.get(i); itemsList.add(appName); // remove list entry lv.setItemChecked(i, false); adapter.remove(appName); } } adapter.notifyDataSetChanged(); new CandySizer.SlimDeleter().execute(itemsList.toArray(new String[itemsList.size()])); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for cancel dialog.cancel(); } }); } else if (id == REBOOT_DIALOG) { // create warning dialog alert.setMessage(R.string.reboot).setTitle(R.string.caution).setCancelable(true) .setPositiveButton(R.string.reboot_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for ok try { dos.writeBytes("reboot"); dos.flush(); dos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).setNegativeButton(R.string.reboot_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // action for cancel dialog.cancel(); } }); } // show warning dialog alert.show(); }
From source file:com.conferenceengineer.android.iosched.ui.SessionsFragment.java
private List<Integer> getCheckedSessionPositions() { List<Integer> checkedSessionPositions = new ArrayList<Integer>(); ListView listView = getListView(); if (listView == null) { return checkedSessionPositions; }//ww w . j a va 2 s . c om SparseBooleanArray checkedPositionsBool = listView.getCheckedItemPositions(); for (int i = 0; i < checkedPositionsBool.size(); i++) { if (checkedPositionsBool.valueAt(i)) { checkedSessionPositions.add(checkedPositionsBool.keyAt(i)); } } return checkedSessionPositions; }
From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); screenStep = ScreenStep.MENU;/*from www .ja va 2 s . co m*/ getSupportActionBar().setSubtitle(Constants.getSelectedCourseShortName()); getSupportActionBar().setIcon(R.drawable.test); tagsAnswersTypeItemClickListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ListView lv = (ListView) parent; int childCount = lv.getCount(); SparseBooleanArray checkedItems = lv.getCheckedItemPositions(); boolean allChecked = true; if (position == 0) { for (int i = 1; i < childCount; i++) { lv.setItemChecked(i, checkedItems.get(0, false)); } } else { for (int i = 1; i < childCount; i++) { if (!checkedItems.get(i, false)) { allChecked = false; } } if (allChecked) { lv.setItemChecked(0, true); } else { lv.setItemChecked(0, false); } } } }; tfAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); tfAdapter.add(getString(R.string.trueMsg)); tfAdapter.add(getString(R.string.falseMsg)); String selection = "id=" + Long.toString(Constants.getSelectedCourseCode()); Cursor dbCursor = dbHelper.getDb().getCursor(Constants.DB_TABLE_TEST_CONFIG, selection, null); startManagingCursor(dbCursor); if (dbCursor.getCount() > 0) { if (isDebuggable) { Log.d(TAG, "selectedCourseCode = " + Long.toString(Constants.getSelectedCourseCode())); } test = (Test) dbHelper.getRow(Constants.DB_TABLE_TEST_CONFIG, "id", Long.toString(Constants.getSelectedCourseCode())); if (test != null) { selectNumQuestions(); } else { Toast.makeText(this, R.string.testNoQuestionsCourseMsg, Toast.LENGTH_LONG).show(); finish(); } } else { Toast.makeText(this, R.string.testNoQuestionsMsg, Toast.LENGTH_LONG).show(); finish(); } setResult(RESULT_OK); }
From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java
/** * Function to set the tags that will be present in the test *//* w w w. j a v a 2 s. co m*/ private void setTags() { ListView checkBoxesList = (ListView) findViewById(R.id.testTagsList); TagsArrayAdapter tagsAdapter = (TagsArrayAdapter) checkBoxesList.getAdapter(); int childsCount = checkBoxesList.getCount(); SparseBooleanArray checkedItems = checkBoxesList.getCheckedItemPositions(); tagsList = new ArrayList<TestTag>(); //If "All tags" item checked, add the whole list to the list of selected tags if (checkedItems.get(0, false)) { tagsList.add(new TestTag(0, null, "all", 0)); //If "All tags" item is not checked, add the selected items to the list of selected tags } else { for (int i = 0; i < childsCount; i++) { if (checkedItems.get(i, false)) { tagsList.add(tagsAdapter.getItem(i)); } } } if (isDebuggable) { Log.d(TAG, "tagsList=" + tagsList.toString()); } //If no tags selected, show a message to notice user if (tagsList.isEmpty()) { Toast.makeText(getApplicationContext(), R.string.testNoTagsSelectedMsg, Toast.LENGTH_LONG).show(); //If any tag is selected, show the answer types selection screen } else { selectAnswerTypes(); } }