0

I would like to know if there is any way to access a spinner selected item while we set it to hidden ? I've tried spinner.setVisibility(View.GONE) but then the selected item is null. Looks like this method resets selected item to null :/

The reason I need to do it is because I want the spinner to have a value depending on the user logged in (Spring WS) but then I want only to show the spinner if admin mode is activated. It's not active by default and since I need to access this value from other activities (without adding parameters) I can't manage to find a solution.

Thanks forward :)

Dighim
  • 3
  • 2

1 Answers1

1

Instead of View.GONE use View.INVISIBLE or if you want to release the space that the Spinner uses, then you must save the latest selected value of spinner in a variable, you can use one of the bellow ways:

  1. gson-google https://stackoverflow.com/a/18463758/9944300

  2. Also you can use Singleton design pattern Singleton

Amin Soheyli
  • 605
  • 2
  • 7
  • 16
  • Thanks ! I thought of it but the fact that I need to access the item from other activities is a bit complicated. Moreover as you said I need to release the space used by the Spinner. Is there a way to save an Object in preferences or something else that can get carried through the entire application ? Because it seems like you can only store primitives in preferences :/ – Dighim Mar 18 '19 at 17:31
  • EDIT : I just thought of serializing the object in a json string but doesn't seem to be that pretty :/ – Dighim Mar 18 '19 at 17:35
  • I think I'll try to serialize it within a preference, but well it would have been amazing if we could still get a value on GONE visibility :'( Still thanks a lot for your answer ! – Dighim Mar 18 '19 at 23:14