Retain State of TextView Color

38 views Asked by At

I'm rendering some TextViews on a LinearLayout. These TextViews hold times that a user can select. If the user selects it, the TextView's color is set to green. If the user selects the TextView (time) again, then it reverts to grey.

So the behavior should be: If TextView unselected, remain grey. If TextView selected, become green. These TextViews should only change color on the user press.

I've managed to retain the state of the TextView's color whenever I scroll on the LinerLayout. However, if I press back, and leave the activity, the TextViews are all reset to grey.

Is it possible to save the instance of the LinearLayout, and it's elements with Firestore? Please let me know if you have any suggestions.

1

There are 1 answers

0
Alex Mamo On BEST ANSWER

Is it possible to save the instance of the LinearLayout and its elements with Firestore?

No, this is not possible. The LinearLayout is not a supported data-type. What can you do instead, is to store the state of your button in Firestore and keep it always in sync with the server using an EventListener. So every time you select the TextView, update the state on the server. If you leave the activity and you open it again, read the last updated value from the server.