OSDN Git Service

Fix bug in setText
authormariagpuyol <mariagpuyol@google.com>
Tue, 8 Mar 2016 18:37:50 +0000 (10:37 -0800)
committermariagpuyol <mariagpuyol@google.com>
Tue, 8 Mar 2016 19:45:39 +0000 (11:45 -0800)
Bug:27547655
Change-Id: Ia15facda59fab9a8fe9b30f74ddd085bc26871af

core/java/android/preference/EditTextPreference.java

index ff37042..9467c22 100644 (file)
@@ -49,6 +49,7 @@ public class EditTextPreference extends DialogPreference {
     private EditText mEditText;
     
     private String mText;
+    private boolean mTextSet;
 
     public EditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
@@ -85,15 +86,16 @@ public class EditTextPreference extends DialogPreference {
      * @param text The text to save
      */
     public void setText(String text) {
-        final boolean wasBlocking = shouldDisableDependents();
-        
-        mText = text;
-        
-        persistString(text);
-        
-        final boolean isBlocking = shouldDisableDependents(); 
-        if (isBlocking != wasBlocking) {
-            notifyDependencyChange(isBlocking);
+        // Always persist/notify the first time.
+        final boolean changed = !TextUtils.equals(mText, text);
+        if (changed || !mTextSet) {
+            mText = text;
+            mTextSet = true;
+            persistString(text);
+            if(changed) {
+                notifyDependencyChange(shouldDisableDependents());
+                notifyChanged();
+            }
         }
     }