Single-ion adsorption and switching in carbon nanotubes