In the settings of my application, the custom Preference - SeekBarPreference is used. It looks like this:

The problem is that after each click on the engine (the value does not have to be changed) Control1 and Control2 change places:

This happens in the emulator 2.1. In the emulator with 4.2.2 this problem does not appear. Question: what is the reason for this and what is the difference in this plan between 2.1 and 4.2.2?
Here is the Preference code:
public class SeekBarPreference extends Preference implements OnSeekBarChangeListener { private TextView valueTextView; private int currentValue; private int max; private int min; final private String NAMESPACE="http://schemas.android.com/apk/res/ru.bartwell.myapp"; private int defaultValue; public SeekBarPreference(Context context, AttributeSet attrs) { super(context, attrs); Log.d("SeekBarPreference", "Init"); max = attrs.getAttributeIntValue(NAMESPACE, "max", 99); min = attrs.getAttributeIntValue(NAMESPACE, "min", 0); defaultValue = attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "defaultValue", min); if(defaultValue<min) defaultValue=min; } @Override protected View onCreateView(ViewGroup parent) { currentValue = getPersistedInt(defaultValue)-min; RelativeLayout layout = (RelativeLayout) LayoutInflater.from(getContext()).inflate(R.layout.seek_bar_preference_layout, null); ((TextView) layout.findViewById(R.id.title)).setText(getTitle()); ((TextView) layout.findViewById(R.id.summary)).setText(getSummary()); SeekBar bar = (SeekBar) layout.findViewById(R.id.seekBar); bar.setMax(max-min); bar.setProgress(currentValue); bar.setOnSeekBarChangeListener(this); valueTextView = (TextView) layout.findViewById(R.id.value); valueTextView.setText(String.valueOf(currentValue+min)); return layout; } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { valueTextView.setText(String.valueOf(progress+min)); valueTextView.invalidate(); } public void onStartTrackingTouch(SeekBar seekBar) {} public void onStopTrackingTouch(SeekBar seekBar) { currentValue = seekBar.getProgress(); persistInt(currentValue+min); notifyChanged(); } } Used like this (prefs.xml):
<ru.bartwell.myapp.SeekBarPreference android:key="Control1" android:summary="@string/control1_description" android:title="@string/control1" android:defaultValue="12" sbp:min="1" sbp:max="20" /> <ru.bartwell.myapp.SeekBarPreference android:key="Control2" android:summary="@string/control2_description" android:title="@string/control2" android:defaultValue="3" sbp:min="1" sbp:max="15" /> PrefActivity.java:
public class PrefActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); } }
SharedPreferences.Editorinstead of the standardpersistInt()andgetPersistedInt()? [/ offtop] - falstaf