List of usage examples for android.widget ListView setChoiceMode
public void setChoiceMode(int choiceMode)
From source file:com.nagopy.android.mypkgs.ApplicationListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(this); Context context = getActivity().getApplicationContext(); FilterType filterType = FilterType.valueOf(getArguments().getString(ARG_FILTER_TYPE)); final ApplicationListAdapter applicationListAdapter = new ApplicationListAdapter(context, filterType); setListAdapter(applicationListAdapter); loadApplications();// w ww . java2s. com }
From source file:simonlang.coastdove.usagestatistics.ui.app_details.AppUsageDataListFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); this.loaderID = 100; ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override// w ww . j a v a2 s .co m public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { listAdapter().toggleSelected(position); mode.setTitle(listAdapter().selectedCount() + ""); listAdapter().notifyDataSetChanged(); } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.app_usage_data_context_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.item_context_delete: List<AppUsageDataUIContainer> selectedItems = listAdapter().getSelectedItems(); List<Integer> selectedItemsPrimaryKeys = new LinkedList<>(); for (AppUsageDataUIContainer selectedItem : selectedItems) selectedItemsPrimaryKeys.add(selectedItem.id); new SQLiteDataRemover(getActivity(), selectedItemsPrimaryKeys).run(); Toast toast = Toast.makeText(getActivity(), getString(R.string.toast_data_removed), Toast.LENGTH_SHORT); toast.show(); mode.finish(); getLoaderManager().restartLoader(loaderID, getArguments(), AppUsageDataListFragment.this); getListView().invalidate(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { listAdapter().resetSelected(); } }); }
From source file:com.psu.capstonew17.pdxaslapp.CreateEditDeckActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_edit_deck); Button subButton = (Button) findViewById(R.id.bttn_submit); subButton.setOnClickListener(this); textBox = (EditText) findViewById(R.id.deckNameField); deckManager = ExternalDeckManager.getInstance(this); allCards = deckManager.getDefaultDeck().getCards(); cardStructs = new ArrayList<>(); if (allCards.size() > 0) findViewById(R.id.noCardsText).setVisibility(View.GONE); //if there's a bundle to grab, then the user is editing a deck if (getIntent().hasExtra(CreateEditDeleteDeckActivity.CHECKED_DECK)) { Bundle bundle = getIntent().getExtras(); if (bundle != null) { //get the selected deck to edit deck = deckManager.getDecks(bundle.getString(CreateEditDeleteDeckActivity.CHECKED_DECK)).get(0); //get all the card in the deck the user is editing cardsInDeck = deck.getCards(); //this will affect what happens when the user hits submit or create //in this case the deck will be updated and commited editMode = true;/*from w ww .ja va 2 s. c o m*/ //button should say "submit" if the user is editing subButton.setText(R.string.button_submit); //set the edit text box to the name of the deck textBox.append(deck.getName()); } //if not, then they're creating a deck } else { //this is a new deck, so there aren't any card currently cardsInDeck = new ArrayList<>(); //since this is being set to false a new deck will be created when the user hits create/submit editMode = false; //the user is creating, so the button should say "create" subButton.setText(R.string.button_create); } //create the CardStructs and set them to selected if the specific card //already exists in the deck. fi this is a new deck then they will all be set to false for (Card curr : allCards) { Boolean contains = cardsInDeck.contains(curr); ListRow cardStruct = new ListRow(curr.getAnswer(), contains); cardStructs.add(cardStruct); } //set list view option, set adapter ListView cardListView = (ListView) findViewById(R.id.list_items); cardListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); CustomArrayListAdapter adapter = new CustomArrayListAdapter(this, R.layout.list_row, cardStructs); cardListView.setAdapter(adapter); cardListView.setItemsCanFocus(false); }
From source file:com.jhk.whysoformal.activity.moveMove.fragment.MoveMoveFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); ListView listView = (ListView) view.findViewById(android.R.id.list); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override/*from w ww . j av a 2 s . c om*/ public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { } }); return view; }
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.JSONAdapterFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ListView lv = (ListView) inflater.inflate(R.layout.listview, container, false); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(new OnCabMultiChoiceModeListener()); return lv;//from ww w. java 2s . c o m }
From source file:de.stadtrallye.rallyesoft.fragments.AssistantGroupsFragment.java
private void restoreChoice(ListView list) { Integer pos = groupAdapter.findPosition(assistant.getGroup()); if (pos != null) { list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(pos, true);// ww w .j a v a 2 s . c o m } }
From source file:org.jraf.android.bikey.app.ride.list.RideListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); setEmptyText(getString(R.string.ride_list_empty)); ListView listView = getListView(); listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override// w ww. jav a 2 s. c o m public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.setTitle(R.string.ride_list_title); int quantity = getListView().getCheckedItemCount(); mode.setSubtitle( getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity)); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.ride_list_contextual, menu); return true; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { int quantity = getListView().getCheckedItemCount(); mode.setSubtitle( getResources().getQuantityString(R.plurals.ride_list_cab_subtitle, quantity, quantity)); // Enable share / edit if only one item is selected (can't share / edit several items at the same time) mode.getMenu().findItem(R.id.action_share).setVisible(quantity == 1); mode.getMenu().findItem(R.id.action_edit).setVisible(quantity == 1); // Enable merge only if several items are selected mode.getMenu().findItem(R.id.action_merge).setVisible(quantity > 1); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { long[] checkedItemIds = getListView().getCheckedItemIds(); long checkedItemId = checkedItemIds[0]; Uri checkedItemUri = ContentUris.withAppendedId(RideColumns.CONTENT_URI, checkedItemId); switch (item.getItemId()) { case R.id.action_delete: getCallbacks().showDeleteDialog(checkedItemIds); mode.finish(); return true; case R.id.action_share: getCallbacks().showShareDialog(checkedItemUri); mode.finish(); return true; case R.id.action_edit: getCallbacks().edit(checkedItemUri); mode.finish(); return true; case R.id.action_merge: getCallbacks().showMergeDialog(checkedItemIds); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); }
From source file:com.thalespf.library.wizardmaker.wizard.internal.ui.ReviewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); TextView titleView = (TextView) rootView.findViewById(android.R.id.title); titleView.setText(R.string.review);//from w w w .ja va 2s . c om titleView.setTextColor(getResources().getColor(R.color.review_green)); mCurrentReviewItems = getPagesReviews(); ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(mReviewAdapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; }
From source file:eu.geopaparazzi.library.forms.FormListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); List<String> fragmentTitles = mFragmentListSupporter.getListTitles(); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1, fragmentTitles.toArray(new String[fragmentTitles.size()])); int color = Compat.getColor(getActivity(), R.color.formcolor); int[] colors = { 0, color, 0 }; ListView listView = getListView(); listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); listView.setDividerHeight(2);/*from www . j av a 2 s . c o m*/ listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setFocusableInTouchMode(true); StateListDrawable selector = new StateListDrawable(); selector.addState(new int[] { -android.R.attr.state_pressed }, new ColorDrawable(Compat.getColor(getContext(), R.color.main_selection))); listView.setSelector(selector); setListAdapter(adapter); if (fragmentTitles.size() > 0) listView.setItemChecked(0, true); }
From source file:id.ridon.keude.views.fragments.SelectLocalAppsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.no_applications_found)); packageManager = getActivity().getPackageManager(); defaultAppIcon = getActivity().getResources().getDrawable(android.R.drawable.sym_def_app_icon); selectLocalAppsActivity = (SelectLocalAppsActivity) getActivity(); ListView listView = getListView(); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.select_local_apps_list_item, null,/*from w ww. j a va 2 s. c o m*/ new String[] { InstalledAppProvider.DataColumns.APPLICATION_LABEL, InstalledAppProvider.DataColumns.APP_ID, }, new int[] { R.id.application_label, R.id.package_name, }, 0); adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == cursor.getColumnIndex(InstalledAppProvider.DataColumns.APP_ID)) { String packageName = cursor.getString(columnIndex); TextView textView = (TextView) view.findViewById(R.id.package_name); textView.setText(packageName); LinearLayout ll = (LinearLayout) view.getParent().getParent(); ImageView iconView = (ImageView) ll.getChildAt(0); Drawable icon; try { icon = packageManager.getApplicationIcon(packageName); } catch (PackageManager.NameNotFoundException e) { icon = defaultAppIcon; } iconView.setImageDrawable(icon); return true; } return false; } }); setListAdapter(adapter); setListShown(false); // start out with a progress indicator // either reconnect with an existing loader or start a new one getLoaderManager().initLoader(0, null, this); // build list of existing apps from what is on the file system if (KeudeApp.selectedApps == null) { HashSet<String> selectedApps = new HashSet<String>(); for (String filename : LocalRepoManager.get(selectLocalAppsActivity).repoDir.list()) { if (filename.matches(".*\\.apk")) { String packageName = filename.substring(0, filename.indexOf("_")); selectedApps.add(packageName); } } KeudeApp.selectedApps = selectedApps; } }