Save the position of the thumb of SeekBar

Is there any way for me to save the position of the thumb where i have moved to before i leave the fragment which is contenting that SeekBar ? Thanks.

Upvotes: 1

Views: 339

Answers (2)

Hayrullah Cansu
Hayrullah Cansu

Reputation: 262

You should define static int value.

Upvotes: 0

Atiq
Atiq

Reputation: 14835

You need to save the position of the Seekbar in SharedPreference and then retrieve it later.

Here is the simple example

EXAMPLE:

SharedPreference mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Editor mEditor = mSharedPrefs.edit();
int mProgress = mSeekBar.getProgress();
mEditor.putInt("SeekBarPosition", mProgress).commit();

and then retrieve them like this

int mProgress = mSharedPrefs.getInt("mMySeekBarProgress", 0);
mSeekBar.setProgress(mProgress);

Upvotes: 3

Related Questions