【慢慢学Android】:10.处理listview长按事件,删除所选项

listview.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id) {
				String item = (String) listview.getItemAtPosition(position);

				SharedPreferences Addresses = getSharedPreferences(FileListenerActivity.PREFS_NAME, 0);
				SharedPreferences.Editor editor = Addresses.edit();
				editor.remove(item);
				editor.commit();
				
				Toast.makeText(getBaseContext(), item + "被删除了",
						Toast.LENGTH_SHORT).show();
				
				 list.remove(item);
				 adapter.notifyDataSetChanged();

				return true;
			}

		});

  

原文地址:https://www.cnblogs.com/VortexPiggy/p/2537684.html