androidandroid-preferencesandroid-seekbarpreferencefragmentseekbarpreference

Seek Bar Preference dont update its value


With following documentation I succesed to implement seek bar preference to preference fragment. But I am stuck at handling seek bar preference change.

The seekbar change its value when the tracking touch released. It doesnt change its value continuously while tracking touch held and sliding.

Even though documentation says there is a "setUpdatesContinuously(boolean)" method, Android Studio can not resolve it. (https://developer.android.com/reference/androidx/preference/SeekBarPreference.html#setUpdatesContinuously(boolean))

Mygradle

implementation 'androidx.preference:preference:1.0.0' 

My Imports

import androidx.preference.Preference;  
import androidx.preference.SeekBarPreference;  

My preference.xml

<androidx.preference.SeekBarPreference
                app:key="change_fact_counts"
                app:icon="@drawable/ic_lockscreen"
                android:layout="@layout/seekbar_preference_layout"
                android:title = "Facts"
                app:showSeekBarValue="true"
                />

My Seekbar Preference Layout

<SeekBar
android:id="@+id/seekbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:max="50"
android:min="1"
android:textSize="@dimen/preference_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@android:id/title"
app:layout_constraintWidth_percent=".8"
android:paddingStart="8dp" />

My Preference Fragment

public class SettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
    SeekBarPreference factCounts;



  @Override
        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    factCounts =(SeekBarPreference) findPreference("change_fact_counts");
    }}

Thank you for reading this. Any help is appreciated


Solution

  • I unsderstand now it was my fault. I just read the release notes of Google. I saw "setUpdatesContinuously(boolean)" method added with 'androidx.preference:preference:1.1.0' library.

    So with changing implementation Android Studio started to work as it must. I hope whomever across with same problem it helps.