List of usage examples for android.widget ListView setItemChecked
public void setItemChecked(int position, boolean value)
From source file:com.ternup.caddisfly.fragment.ResultFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle(R.string.result); mContext = getActivity();//from w ww .jav a 2 s . c o m mPpmText = (TextView) view.findViewById(R.id.ppmText); mDateView = (TextView) view.findViewById(R.id.testDate); mTitleView = (TextView) view.findViewById(R.id.titleView); mResultTextView = (TextView) view.findViewById(R.id.result); //mResultIcon = (ImageView) view.findViewById(R.id.resultIcon); mAddressText = (TextView) view.findViewById(R.id.address1); mAddress2Text = (TextView) view.findViewById(R.id.address2); mAddress3Text = (TextView) view.findViewById(R.id.address3); mSourceText = (TextView) view.findViewById(R.id.sourceType); ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(-1, true); drawerList.setSelection(-1); folderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); mId = getArguments().getLong(getString(R.string.currentTestId)); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); /*Button deleteButton = (Button) view.findViewById(R.id.deleteButton); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertUtils.askQuestion(getActivity(), R.string.delete, R.string.areYouSure, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { FileUtils.deleteFolder(getActivity(), mLocationId, folderName); Uri uri = ContentUris .withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); int value = 0; int counter = 0; SharedPreferences.Editor editor = sharedPreferences.edit(); while (value != -1) { value = sharedPreferences .getInt(String.format("result_%d_%d", mId, counter), -1); if (value > -1) { editor.remove(String.format("result_%d_%d", mId, counter)); editor.commit(); counter++; } } goBack(); } }, null ); } }); Button sendButton = (Button) view.findViewById(R.id.sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (NetworkUtils.checkInternetConnection(mContext)) { if (progressDialog == null) { progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Sending..."); progressDialog.setCancelable(false); } progressDialog.show(); postResult("testresults"); } } }); */ ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, mLocationId); File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, folderName, false)); if (!directory.exists()) { Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); goBack(); } else if (filePaths.size() > 0) { displayResult(); } else { FileUtils.deleteFolder(getActivity(), mLocationId, folderName); } }
From source file:com.thatkawaiiguy.meleehandbook.activity.SearchResultsActivity.java
private void showDialog() { AlertDialog dialog;//from w w w . j av a 2 s . c om checked = new boolean[] { prefs.getBoolean(TECH_KEY, true), prefs.getBoolean(CHAR_KEY, true), prefs.getBoolean(FUN_KEY, true), prefs.getBoolean(MAP_KEY, true), prefs.getBoolean(TERM_KEY, true), prefs.getBoolean(UNIQUE_KEY, true) }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Select which list items you want to appear"); builder.setMultiChoiceItems(R.array.filter_options, checked, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) { AlertDialog d = (AlertDialog) dialog; ListView v = d.getListView(); int i = 0; while (i < checked.length) { v.setItemChecked(i, checked[i]); i++; } checked[indexSelected] = isChecked; } }).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { prefs.edit().putBoolean(TECH_KEY, checked[0]).apply(); prefs.edit().putBoolean(CHAR_KEY, checked[1]).apply(); prefs.edit().putBoolean(FUN_KEY, checked[2]).apply(); prefs.edit().putBoolean(MAP_KEY, checked[3]).apply(); prefs.edit().putBoolean(TERM_KEY, checked[4]).apply(); prefs.edit().putBoolean(UNIQUE_KEY, checked[5]).apply(); checked = new boolean[] { prefs.getBoolean(TECH_KEY, true), prefs.getBoolean(CHAR_KEY, true), prefs.getBoolean(FUN_KEY, true), prefs.getBoolean(MAP_KEY, true), prefs.getBoolean(TERM_KEY, true), prefs.getBoolean(UNIQUE_KEY, true) }; search(query); } }).setNegativeButton("Cancel", null); dialog = builder.create();//AlertDialog dialog; create like this outside onClick dialog.show(); }
From source file:com.github.runoshun.in_app_survey.ui.QuestionFragment.java
private void onMultiChoiceItemClick(MultiChoiceQuestion question, ListView listView, int position) { SparseBooleanArray checkedItems = listView.getCheckedItemPositions(); List<Integer> selectedPositions = new ArrayList<>(); int count = listView.getAdapter().getCount(); for (int i = 0; i < count; ++i) { if (checkedItems.get(i)) { selectedPositions.add(i);// w w w . j a v a 2s . c o m } } if (selectedPositions.size() > question.maxChoices) { listView.setItemChecked(position, false); selectedPositions.remove((Integer) position); } int[] selected = new int[selectedPositions.size()]; for (int i = 0; i < selected.length; ++i) { selected[i] = selectedPositions.get(i); } if (selectedPositions.size() >= question.minChoices) { question.saveAnswer(selected); } else { question.saveAnswer(null); } }
From source file:com.ushahidi.android.app.ui.tablet.ListReportFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { l.setItemChecked(position, true); if (fetchedReportAdapter == adapter.getAdapter(position - 1)) { int itemAt = (adapter.getCount() - position); launchViewReport((fetchedReportAdapter.getCount() - itemAt) - 1); } else if (pendingReportAdapter == adapter.getAdapter(position - 1)) { int itemPosition = pendingReportAdapter.getCount() - position; int itemAt = (pendingReportAdapter.getCount() - itemPosition) - 1; launchAddReport((int) pendingReportAdapter.getItem(itemAt - 1).getId()); }/*from w ww.j a v a 2s. c o m*/ }
From source file:com.myandroidremote.AccountsActivity.java
/** * Sets up the 'connect' screen content. *///w ww . ja va 2 s. com private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { showLoadingScreen(); } }); builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Register in the background and terminate the activity mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); register((String) account.getText()); // show connecting showLoadingScreen(); } }); final Button exitButton = (Button) findViewById(R.id.exit); exitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); } }
From source file:com.android.deskclock.RingtonePickerDialogFragment.java
@Override public void onLoadFinished(Loader<RingtoneManager> loader, RingtoneManager ringtoneManager) { // Swap in the new ringtone manager. mRingtoneAdapter.setRingtoneManager(ringtoneManager); // Preserve the selected ringtone. final ListView listView = mDialog.getListView(); final int checkedPosition = mRingtoneAdapter.getRingtonePosition(mSelectedRingtoneUri); if (checkedPosition != ListView.INVALID_POSITION) { listView.setItemChecked(checkedPosition, true); // Also scroll the list to the selected ringtone (this method is poorly named). listView.setSelection(checkedPosition); } else {//from w w w. j av a 2s .co m // Can't find the selected ringtone, clear the current selection. mSelectedRingtoneUri = null; listView.clearChoices(); } // Enable the positive button if we have a valid selection (Note: the positive button may // be null if this callback returns before onStart). final View positiveButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE); if (positiveButton != null) { positiveButton.setEnabled(mSelectedRingtoneUri != null); } // On M devices the checked view's drawable state isn't updated properly when it is first // bound, so we must use a blunt approach to force it to refresh correctly. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { listView.post(new Runnable() { @Override public void run() { for (int i = listView.getChildCount() - 1; i >= 0; --i) { listView.getChildAt(i).refreshDrawableState(); } } }); } }
From source file:com.example.android.wizardpager.wizard.ui.dataorbs.SingleChoiceFragmentWithDataOrbs.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new DataOrbAdapter(getActivity(), mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override// www . java 2 s .c o m public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).displayString.equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:com.roamprocess1.roaming4world.ui.calllog.CallLogListFragment.java
@Override public void viewDetails(int position, long[] callIds) { ListView lv = getListView(); if (mMode != null) { lv.setItemChecked(position, !lv.isItemChecked(position)); mMode.invalidate();/*from ww w . j ava2 s . com*/ // Don't see details in this case System.out.println("CallLogListFragment Step 12"); return; } if (mDualPane) { System.out.println("CallLogListFragment === mDualPane"); System.out.println("CallLogListFragment Step 13"); // If we are not currently showing a fragment for the new // position, we need to create and install a new one. CallLogDetailsFragment df = new CallLogDetailsFragment(); Bundle bundle = new Bundle(); bundle.putLongArray(CallLogDetailsFragment.EXTRA_CALL_LOG_IDS, callIds); df.setArguments(bundle); // Execute a transaction, replacing any existing fragment // with this one inside the frame. System.out.println("CallLogListFragment Step 14"); try { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.details, df, null); ft.addToBackStack(null); System.out.println("CallLogListFragment Step 15"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } catch (Exception e) { // TODO: handle exception } getListView().setItemChecked(position, true); } else { Intent it = new Intent(getActivity(), CallLogDetailsActivity.class); it.putExtra(CallLogDetailsFragment.EXTRA_CALL_LOG_IDS, callIds); System.out.println("CallLogListFragment Step 16"); try { getActivity().startActivity(it); } catch (Exception e) { // TODO: handle exception } } }
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);// w w w. ja v 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:org.flerda.android.honeypad.NoteListFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { if (!mIsV11) { /*// www . j a v a2 s .c om * Slight Hack: Multiselect lists are automatically * Checked/unchecked. If the item was previously checked, it will * now be unchecked, etc. We compensate for that here. */ l.setItemChecked(position, !l.isItemChecked(position)); } mCurrentActivePosition = position; mContainerCallback.onNoteSelected(ContentUris.withAppendedId(NotesProvider.CONTENT_URI, id)); }