Domanda

Hey I was wondering how I can save the state of a specific togglebutton's state in a ListView. So that whenever my activity is started, those togglebuttons would stay checked. Any help is appriciated.

Thankyou

È stato utile?

Soluzione

There are several options for saving data beyond the life cycle of your activity and application. The Storage Guide has a rundown of each, along with their merits. Depending on what your toggle button and list view represent, you may just need to use a Preference Activity, which simplifies the saving and recalling of any settings you've built in to your app.

You can manually save a boolean in your Shared Preferences and recall it when creating the adapter for your list view. There's nothing about the toggle button itself that should be responsible for persisting this state data - it should only be in charge of displaying the state as you tell it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top