简体   繁体   中英

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.

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);

您应该定义静态int值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM