don't double set the dropdown value
idion: set the default value, and then add a callback actual: spinner posts the change to a handler: so it posts after the callback is set. This makes it hard to count actual user interactions without counting the initialization. Bug: 21530764 Change-Id: I3ff8319edb374d8d7c10982512054f303c69a5ec
This commit is contained in:
@@ -36,6 +36,7 @@ public class DropDownPreference extends Preference {
|
|||||||
private final ArrayList<Object> mValues = new ArrayList<Object>();
|
private final ArrayList<Object> mValues = new ArrayList<Object>();
|
||||||
|
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
private int mSelectedPosition = -1;
|
||||||
|
|
||||||
public DropDownPreference(Context context) {
|
public DropDownPreference(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -54,7 +55,7 @@ public class DropDownPreference extends Preference {
|
|||||||
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
|
||||||
setSelectedItem(position);
|
setSelectedItem(position, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,11 +92,19 @@ public class DropDownPreference extends Preference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedItem(int position) {
|
public void setSelectedItem(int position) {
|
||||||
|
setSelectedItem(position, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedItem(int position, boolean fromSpinner) {
|
||||||
|
if (fromSpinner && position == mSelectedPosition) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Object value = mValues.get(position);
|
final Object value = mValues.get(position);
|
||||||
if (mCallback != null && !mCallback.onItemSelected(position, value)) {
|
if (mCallback != null && !mCallback.onItemSelected(position, value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mSpinner.setSelection(position);
|
mSpinner.setSelection(position);
|
||||||
|
mSelectedPosition = mSpinner.getSelectedItemPosition();
|
||||||
setSummary(mAdapter.getItem(position));
|
setSummary(mAdapter.getItem(position));
|
||||||
final boolean disableDependents = value == null;
|
final boolean disableDependents = value == null;
|
||||||
notifyDependencyChange(disableDependents);
|
notifyDependencyChange(disableDependents);
|
||||||
|
Reference in New Issue
Block a user