List of usage examples for android.widget ArrayAdapter remove
public void remove(@Nullable T object)
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.CalibrateListActivity.java
/** * Load the calibrated swatches from the calibration text file * * @param callback callback to be initiated once the loading is complete *//*from w w w .ja v a 2 s .c om*/ private void loadCalibration(@NonNull final Context context, @NonNull final Handler.Callback callback) { try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, R.layout.row_text); final File path = FileHelper.getFilesDir(FileHelper.FileType.CALIBRATION, CaddisflyApp.getApp().getCurrentTestInfo().getId()); File[] listFilesTemp = null; if (path.exists() && path.isDirectory()) { listFilesTemp = path.listFiles(); } final File[] listFiles = listFilesTemp; if (listFiles != null && listFiles.length > 0) { Arrays.sort(listFiles); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); try { final List<Swatch> swatchList = SwatchHelper.loadCalibrationFromFile(getBaseContext(), fileName); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { SwatchHelper.saveCalibratedSwatches(context, swatchList); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } catch (Exception ex) { AlertUtil.showError(context, R.string.error, getString(R.string.errorLoadingFile), null, R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }, null, null); } } }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alertDialog.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtil.askQuestion(context, R.string.delete, R.string.deleteConfirm, R.string.delete, R.string.cancel, true, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtil.deleteFile(path, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); alertDialog.dismiss(); Toast.makeText(context, R.string.deleted, Toast.LENGTH_SHORT) .show(); } }, null); return true; } }); } }); alertDialog.show(); } else { AlertUtil.showMessage(context, R.string.notFound, R.string.loadFilesNotAvailable); } } catch (ActivityNotFoundException ignored) { } callback.handleMessage(null); }
From source file:com.googlecode.CallerLookup.Main.java
public void doRemove() { final Context context = this; final String name = mLookup.getSelectedItem().toString(); AlertDialog.Builder confirm = new AlertDialog.Builder(context); confirm.setTitle(R.string.RemoveTitle); confirm.setMessage(R.string.RemoveMessage); confirm.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override/* w ww.j a v a 2s. c o m*/ public void onClick(DialogInterface dialog, int which) { removeUserLookupEntry(name); doCustomize(); ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter(); adapter.remove(name); } }); confirm.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); confirm.show(); }
From source file:com.spatialnetworks.fulcrum.widget.DynamicListView.java
private void swapElements(int indexOne, int indexTwo) { ListAdapter listAdapter = getAdapter(); if (listAdapter instanceof WrapperListAdapter) { WrapperListAdapter wrapperListAdapter = (WrapperListAdapter) listAdapter; listAdapter = wrapperListAdapter.getWrappedAdapter(); }//from w w w .j a va 2 s . co m if (!(listAdapter instanceof ArrayAdapter)) { throw new RuntimeException("DynamicListView can only swap elements using an ArrayAdapter"); } else { ArrayAdapter arrayAdapter = (ArrayAdapter) listAdapter; Object obj2 = arrayAdapter.getItem(indexTwo); //noinspection unchecked arrayAdapter.remove(obj2); //noinspection unchecked arrayAdapter.insert(obj2, indexOne); } }
From source file:org.akvo.caddisfly.ui.activity.MainActivity.java
@Override public void onLoadCalibration(final Handler.Callback callback) { final Context context = this; final MainApp mainApp = (MainApp) this.getApplicationContext(); try {/*w ww.j a v a2 s. c om*/ AlertDialog.Builder builderSingle = new AlertDialog.Builder(context); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.select_dialog_singlechoice); File external = Environment.getExternalStorageDirectory(); final String folderName = Config.CALIBRATE_FOLDER_NAME; String path = external.getPath() + folderName; File folder = new File(path); if (folder.exists()) { final File[] listFiles = folder.listFiles(); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); final ArrayList<Integer> swatchList = new ArrayList<Integer>(); final ArrayList<String> rgbList = FileUtils.loadFromFile(fileName); if (rgbList != null) { for (String rgb : rgbList) { swatchList.add(ColorUtils.getColorFromRgb(rgb)); } (new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mainApp.saveCalibratedSwatches(mainApp.currentTestInfo.getCode(), swatchList); mainApp.setSwatches(mainApp.currentTestInfo.getCode()); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); for (int i = 0; i < mainApp.rangeIntervals.size(); i++) { int index = i * mainApp.rangeIncrementStep; ColorUtils.autoGenerateColors(index, mainApp.currentTestInfo.getCode(), mainApp.colorList, mainApp.rangeIncrementStep, editor, 0); } editor.apply(); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } } }); final AlertDialog alert = builderSingle.create(); alert.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alert.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtils.askQuestion(context, R.string.delete, R.string.selectedWillBeDeleted, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtils.deleteFile(folderName, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); } }); return true; } }); } }); alert.show(); } else { AlertUtils.showMessage(context, R.string.notFound, R.string.noSavedCalibrations); } } catch (ActivityNotFoundException e) { AlertUtils.showMessage(context, R.string.error, R.string.updateRequired); } callback.handleMessage(null); }
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(); }/* ww w .j ava 2s. c om*/ }); // 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.Candy.sizer.CandySizer.java
private void selectDialog(final ArrayList<String> sysAppProfile, final ArrayAdapter<String> adapter) { AlertDialog.Builder select = new AlertDialog.Builder(getActivity()); select.setItems(R.array.slimsizer_profile_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' argument contains the index position // of the selected item short state = sdAvailable(); File path = new File(Environment.getExternalStorageDirectory() + "/Slim"); File savefile = new File(path + "/slimsizer.stf"); if (which == 0) { // load profile action if (state >= 1) { String profile; try { // read savefile and create arraylist profile = new Scanner(savefile, "UTF-8").useDelimiter("\\A").next(); ArrayList<String> profileState = new ArrayList<String>( Arrays.asList(profile.split(", "))); // create arraylist of unique entries in // sysAppProfile (currently installed apps) ArrayList<String> deleteList = new ArrayList<String>(); for (String item : sysAppProfile) { if (!profileState.contains(item)) { deleteList.add(item); }//from w ww .j a v a 2 s.c o m } // delete all entries in deleteList ArrayList<String> itemsList = new ArrayList<String>(); for (int i = deleteList.size() - 1; i > 0; i--) { String item = deleteList.get(i); itemsList.add(item); // remove list entry adapter.remove(item); } adapter.notifyDataSetChanged(); new CandySizer.SlimDeleter().execute(itemsList.toArray(new String[itemsList.size()])); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnoread)); } } else if (which == 1) { // save profile action if (state == 2) { try { // create directory if it doesnt exist if (!path.exists()) { path.mkdirs(); } // create string from arraylists String lists = sysAppProfile.toString(); lists = lists.replace("][", ","); lists = lists.replace("[", ""); lists = lists.replace("]", ""); // delete savefile if it exists (overwrite) if (savefile.exists()) { savefile.delete(); } // create savefile and output lists to it FileWriter outstream = new FileWriter(savefile); BufferedWriter save = new BufferedWriter(outstream); save.write(lists); save.close(); // check for success if (savefile.exists()) { toast(getResources().getString(R.string.sizer_message_filesuccess)); } else { toast(getResources().getString(R.string.sizer_message_filefail)); } } catch (IOException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnowrite)); } } } }); select.show(); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void editDontWantToSee() { if (!SettingConstants.UPDATING_FILTER) { Set<String> currentExclusions = PrefUtils.getStringSetValue(R.string.I_DONT_WANT_TO_SEE_ENTRIES, null); final ArrayList<ExclusionEdit> mCurrentExclusionList = new ArrayList<TvBrowser.ExclusionEdit>(); if (currentExclusions != null && !currentExclusions.isEmpty()) { for (String exclusion : currentExclusions) { mCurrentExclusionList.add(new ExclusionEdit(exclusion)); }// ww w . ja v a 2 s. c om } Collections.sort(mCurrentExclusionList); final ArrayAdapter<ExclusionEdit> exclusionAdapter = new ArrayAdapter<TvBrowser.ExclusionEdit>( TvBrowser.this, android.R.layout.simple_list_item_1, mCurrentExclusionList); View view = getLayoutInflater().inflate(R.layout.dont_want_to_see_exclusion_edit_list, getParentViewGroup(), false); ListView list = (ListView) view.findViewById(R.id.dont_want_to_see_exclusion_list); list.setAdapter(exclusionAdapter); final Runnable cancel = new Runnable() { @Override public void run() { } }; AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ExclusionEdit edit = exclusionAdapter.getItem(position); View editView = getLayoutInflater().inflate(R.layout.dont_want_to_see_edit, getParentViewGroup(), false); final TextView exclusion = (TextView) editView.findViewById(R.id.dont_want_to_see_value); final CheckBox caseSensitive = (CheckBox) editView .findViewById(R.id.dont_want_to_see_case_sensitve); exclusion.setText(edit.mExclusion); caseSensitive.setSelected(edit.mIsCaseSensitive); Runnable editPositive = new Runnable() { @Override public void run() { if (exclusion.getText().toString().trim().length() > 0) { edit.mExclusion = exclusion.getText().toString(); edit.mIsCaseSensitive = caseSensitive.isSelected(); exclusionAdapter.notifyDataSetChanged(); } } }; showAlertDialog(getString(R.string.action_dont_want_to_see), null, editView, null, editPositive, null, cancel, false, false); } }; list.setOnItemClickListener(onClickListener); list.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { getMenuInflater().inflate(R.menu.don_want_to_see_context, menu); MenuItem item = menu.findItem(R.id.dont_want_to_see_delete); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { ExclusionEdit edit = exclusionAdapter .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); exclusionAdapter.remove(edit); exclusionAdapter.notifyDataSetChanged(); return true; } }); } }); Thread positive = new Thread() { @Override public void run() { SettingConstants.UPDATING_FILTER = true; final NotificationCompat.Builder builder = new NotificationCompat.Builder(TvBrowser.this); builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setOngoing(true); builder.setContentTitle(getResources().getText(R.string.action_dont_want_to_see)); builder.setContentText( getResources().getText(R.string.dont_want_to_see_refresh_notification_text)); final int notifyID = 2; final NotificationManager notification = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notification.notify(notifyID, builder.build()); updateProgressIcon(true); HashSet<String> newExclusions = new HashSet<String>(); final ArrayList<DontWantToSeeExclusion> exclusionList = new ArrayList<DontWantToSeeExclusion>(); for (ExclusionEdit edit : mCurrentExclusionList) { String exclusion = edit.getExclusion(); newExclusions.add(exclusion); exclusionList.add(new DontWantToSeeExclusion(exclusion)); } new Thread() { public void run() { Cursor programs = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_DATA, new String[] { TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.DATA_KEY_TITLE }, null, null, TvBrowserContentProvider.KEY_ID); programs.moveToPosition(-1); builder.setProgress(programs.getCount(), 0, true); notification.notify(notifyID, builder.build()); ArrayList<ContentProviderOperation> updateValuesList = new ArrayList<ContentProviderOperation>(); int keyColumn = programs.getColumnIndex(TvBrowserContentProvider.KEY_ID); int titleColumn = programs.getColumnIndex(TvBrowserContentProvider.DATA_KEY_TITLE); DontWantToSeeExclusion[] exclusionArr = exclusionList .toArray(new DontWantToSeeExclusion[exclusionList.size()]); while (programs.moveToNext()) { builder.setProgress(programs.getCount(), programs.getPosition(), false); notification.notify(notifyID, builder.build()); String title = programs.getString(titleColumn); boolean filter = UiUtils.filter(getApplicationContext(), title, exclusionArr); long progID = programs.getLong(keyColumn); ContentValues values = new ContentValues(); values.put(TvBrowserContentProvider.DATA_KEY_DONT_WANT_TO_SEE, filter ? 1 : 0); ContentProviderOperation.Builder opBuilder = ContentProviderOperation.newUpdate( ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_DATA_UPDATE, progID)); opBuilder.withValues(values); updateValuesList.add(opBuilder.build()); } notification.cancel(notifyID); programs.close(); if (!updateValuesList.isEmpty()) { try { getContentResolver().applyBatch(TvBrowserContentProvider.AUTHORITY, updateValuesList); UiUtils.sendDontWantToSeeChangedBroadcast(getApplicationContext(), true); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.dont_want_to_see_sync_success, Toast.LENGTH_LONG) .show(); } }); } catch (RemoteException e) { e.printStackTrace(); } catch (OperationApplicationException e) { e.printStackTrace(); } } updateProgressIcon(false); SettingConstants.UPDATING_FILTER = false; } }.start(); Editor edit = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit(); edit.putStringSet(getString(R.string.I_DONT_WANT_TO_SEE_ENTRIES), newExclusions); edit.commit(); } }; showAlertDialog(getString(R.string.action_dont_want_to_see_edit), null, view, null, positive, null, cancel, false, true); } }