How to display values in a SeekBarPreference
Asked Answered
S

2

5

How can I display the seekbar value using a SeekBarPreference?

<PreferenceCategory 
     android:title="Delay between change image">

     <SeekBarPreference
         android:id="@+id/preference_delay_seek_bar"
         android:title="Value"
         android:defaultValue="1"
         android:max="60"/>

</PreferenceCategory>
Scarabaeus answered 3/4, 2014 at 14:36 Comment(0)
S
4

Something like this:

((SeekBarPreference) findPreference(R.id.preference_delay_seek_bar)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    final int progress = Integer.valueOf(String.valueOf(newValue));
    preference.setSummary(String.format("My progress value: %d", progress));
  }
});
Sharisharia answered 4/4, 2014 at 6:36 Comment(1)
Thanks, all work right. But parameter "summary" on seekbarprerefence not work) setTitle help meScarabaeus
S
14

With JetPack I could simply add the following attribute to the SeekBarPreference XML element.

app:showSeekBarValue="true"
Socle answered 4/3, 2020 at 14:58 Comment(0)
S
4

Something like this:

((SeekBarPreference) findPreference(R.id.preference_delay_seek_bar)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
  @Override
  public boolean onPreferenceChange(Preference preference, Object newValue) {
    final int progress = Integer.valueOf(String.valueOf(newValue));
    preference.setSummary(String.format("My progress value: %d", progress));
  }
});
Sharisharia answered 4/4, 2014 at 6:36 Comment(1)
Thanks, all work right. But parameter "summary" on seekbarprerefence not work) setTitle help meScarabaeus

© 2022 - 2024 — McMap. All rights reserved.