List of usage examples for android.widget ListView setChoiceMode
public void setChoiceMode(int choiceMode)
From source file:com.btmura.android.reddit.app.NavigationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) v.findViewById(android.R.id.list); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(this); return v;//from w w w .j av a 2 s . c o m }
From source file:monakhv.android.samlib.AuthorTagsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { helper = new SettingsHelper(this); setTheme(helper.getTheme());// w w w . j av a 2 s . co m super.onCreate(savedInstanceState); setContentView(R.layout.author_tags); author_id = getIntent().getExtras().getInt(AuthorTagsActivity.AUTHOR_ID); ListView listView = getListView(); String[] from = { SQLController.COL_TAG_NAME }; int[] to = { android.R.id.text1 }; Cursor attributesCursor = getCursor(); adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, attributesCursor, from, to, 0); listView.setAdapter(adapter); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setItemsCanFocus(false); loadTagData(); registerForContextMenu(listView); }
From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(isCancelable);//from w ww . j a va 2s . c o m if (TextUtils.isEmpty(positiveText)) { positiveText = "OK"; Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok); } if (TextUtils.isEmpty(negativeText)) { negativeText = "Cancel"; } switch (type) { case DIALOG_TYPE_OK: /*show dialog with positive button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).create(); case DIALOG_TYPE_YES_NO: /*show dialog with positive and negative button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onNegativeButtonClick(identifier); } }).create(); case DATE_DIALOG: /*show date picker dialog*/ return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate); case TIME_DIALOG: /*show time picker dialog*/ return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true); case SIMPLE_LIST_DIALOG: /** * show simple list dialog */ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create(); case SINGLE_CHOICE_LIST_DIALOG: /*show single choice list dialog*/ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create(); case MULTI_CHOICE_LIST_DIALOG: /*show multichoice list dialog*/ Dialog multipleChoice = new Dialog(getActivity()); multipleChoice.setContentView(R.layout.list_multichoice); multipleChoice.setTitle(title); ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Manage selected items here CheckedTextView textView = (CheckedTextView) view; if (textView.isChecked()) { } else { } Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked()); } }); final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_multichoice, dialogList); listView.setAdapter(arraySingleChoiceAdapter); multipleChoice.show(); /*multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } });*/ /* multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ // multipleChoice.create(); // singleChoiceListDialog.setCancelable(false); /* multipleChoice.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { alSelectedItem.add(items[which]); } else { alSelectedItem.remove(items[which]); } } }); multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ return multipleChoice;//.create(); } return null; }
From source file:com.snapshotshopper.SnapshotShopper.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_snapshot_shopper); ListView ShoppingListView = (ListView) findViewById(R.id.ShoppingList); //************************************************************************************************** //Modified from following source: //Source: http://stackoverflow.com/questions/454075enteredText.;4/add-dynamically-elements-to-a-listview-android //Author: Shardul //Author's profile page: http://stackoverflow.com/users/514553/shardul listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, ShoppingListItems);/*from www . j a va 2 s. co m*/ ShoppingListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); ShoppingListView.setItemsCanFocus(false); ShoppingListView.setAdapter(listAdapter); //************************************************************************************************** //Modified from following source: //Source: http://stackoverflow.com/questions/6205808/how-to-handle-long-tap-on-listview-item //Author: Aleadam //Author's profile page: http://stackoverflow.com/users/542701/aleadam ShoppingListView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { String dummy = "edit item entry here"; takePicture(view, dummy); return false; } }); //************************************************************************************************** //************************************************************************************************** }
From source file:com.wizard.ui.DoubleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page_double_choice, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); ((TextView) rootView.findViewById(R.id.ddomain)) .setText(Integer.toString(mPage.getmNumberDomainQuestion())); final List<String> severitylist = new ArrayList<String>(); //set only numbers severitylist.add("0 = None"); severitylist.add("1 = Mild"); severitylist.add("2 = Moderate"); severitylist.add("3 = Severe"); final ListView listViewSeverity = (ListView) rootView.findViewById(R.id.list1); listViewSeverity.setAdapter(new ArrayAdapter<String>(getActivity(), //android.R.layout.simple_list_item_single_choice, R.layout.mylist, android.R.id.text1, severitylist)); /*//from w w w . j a va 2s . c o m setListAdapter(new ArrayAdapter<String>(getActivity(), //android.R.layout.simple_list_item_single_choice, R.layout.mylist, android.R.id.text1, severitylist)); */ listViewSeverity.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final List<String> frequencylist = new ArrayList<String>(); //set only numbers frequencylist.add("1 = Rarely(<1/wk)"); frequencylist.add("2 = Often(1/wk)"); frequencylist.add("3 = Frequent(several times per week)"); frequencylist.add("4 = Very Frequent(daily or all the time)"); final ListView listViewFrequency = (ListView) rootView.findViewById(R.id.list2); /* setListAdapter(new ArrayAdapter<String>(getActivity(), //android.R.layout.simple_list_item_single_choice, R.layout.mylist, android.R.id.text1, frequencylist)); */ listViewFrequency.setAdapter(new ArrayAdapter<String>(getActivity(), //android.R.layout.simple_list_item_single_choice, R.layout.mylist, android.R.id.text1, frequencylist)); listViewFrequency.setChoiceMode(ListView.CHOICE_MODE_SINGLE); /************ * this action is deactivated * */ /*** * * // Pre-select currently selected item. new Handler().post(new Runnable() { @Override public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); *******/ return rootView; }
From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java
/** * Enable or disable export mode./* w w w . j ava 2 s .c o m*/ * * @param exportMode Whether to enable export mode * @param animate Whether to animate the export toolbar */ public void setExportMode(boolean exportMode, boolean animate) { final ListView listView = getListView(); if (exportMode) { listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); } else { setActivateOnItemClick(mTwoPane); for (long id : getListView().getCheckedItemIds()) { listView.setItemChecked(mAdapter.getItemIndex(id), false); } } mAdapter.setMultiChoiceMode(exportMode); listView.setItemChecked(mAdapter.getItemIndex(mActivatedItem), !exportMode && mTwoPane); showExportToolbar(exportMode, animate); mExportMode = exportMode; }
From source file:no.digipost.android.gui.content.UploadActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER); setContentView(R.layout.activity_upload); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from ww w . j a v a 2s . co m getSupportActionBar().setTitle(R.string.upload); getSupportActionBar().setHomeButtonEnabled(true); absolutePath = (TextView) findViewById(R.id.upload_file_path); availableSpace = (TextProgressBar) findViewById(R.id.upload_available_space); listEmpty = (TextView) findViewById(R.id.upload_list_empty); mDirectory = DEFAULT_INITIAL_DIRECTORY; mFiles = new ArrayList<File>(); ListView listView = (ListView) findViewById(R.id.upload_file_list); listView.setEmptyView(listEmpty); listView.setOnItemClickListener(new ListOnItemClickListener()); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setFastScrollEnabled(true); listView.setMultiChoiceModeListener(new UploadMultiChoiceModeListener()); listAdapter = new UploadListAdapter(this, mFiles); listView.setAdapter(listAdapter); content = getIntent().getIntExtra(ApiConstants.UPLOAD, ApplicationConstants.MAILBOX); Permissions.requestWritePermissionsIfMissing(getApplicationContext(), UploadActivity.this); executeSetAccountInfoTask(); }
From source file:org.gnucash.android.ui.account.AccountsListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ActionBar actionbar = getSherlockActivity().getSupportActionBar(); actionbar.setTitle(R.string.title_accounts); if (getActivity() instanceof TransactionsActivity) { actionbar.setDisplayHomeAsUpEnabled(true); } else {/*from ww w . j a va 2 s. c o m*/ actionbar.setDisplayHomeAsUpEnabled(false); } setHasOptionsMenu(true); ListView lv = getListView(); lv.setOnItemLongClickListener(this); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); getLoaderManager().initLoader(0, null, this); }
From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java
/** * Called when Select File was pressed/*from w w w .j a va 2 s. com*/ * * @param view * a button that was pressed */ public void onSelectFileClicked(final View view) { final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/octet-stream"); intent.addCategory(Intent.CATEGORY_OPENABLE); if (intent.resolveActivity(getPackageManager()) != null) { // file browser has been found on the device startActivityForResult(intent, SELECT_FILE_REQ); } else { // there is no any file browser app, let's try to download one final View customView = getLayoutInflater().inflate(R.layout.app_file_browser, null); final ListView appsList = (ListView) customView.findViewById(android.R.id.list); appsList.setAdapter(new FileBrowserAppsAdapter(this)); appsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); appsList.setItemChecked(0, true); new AlertDialog.Builder(this).setTitle(R.string.dfu_alert_no_filebrowser_title).setView(customView) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); } }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final int pos = appsList.getCheckedItemPosition(); if (pos >= 0) { final String query = getResources() .getStringArray(R.array.dfu_app_file_browser_action)[pos]; final Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query)); startActivity(storeIntent); } } }).show(); } }
From source file:org.kontalk.ui.ConversationListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mQueryHandler = new ThreadListQueryHandler(getActivity().getContentResolver()); mListAdapter = new ConversationListAdapter(getActivity(), null, getListView()); mListAdapter.setOnContentChangedListener(mContentChangedListener); ListView list = getListView(); // Check to see if we have a frame in which to embed the details // fragment directly in the containing UI. View detailsFrame = getActivity().findViewById(R.id.fragment_compose_message); mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE; if (mDualPane) { // TODO restore state list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemsCanFocus(true);/*from w w w . j a va2s . co m*/ } setListAdapter(mListAdapter); setMultiChoiceModeListener(this); }