title: Android Acccessibility: How do I change the text read out loud for an EditText View
body: <p>By default, the Accessibility Services will read out the following for an EditText view</p>
  
  <ul>
  <li>If the EditText has a value entered = it will read out that value</li>
  <li>If there is not value entered = it will read out the "hint"</li>
  </ul>
  
  <p>I want it to read out something completely different in both cases.</p>
  
  <p>My xml snippet is </p>
  
  <pre><code>&lt;EditText
      android:id="@+id/my_edit_text"
      android:layout_height="wrap_content"
      android:layout_width="0dp"
      android:layout_weight="1"
      android:editable="false"
      android:focusable="true"
      android:hint="my hint text"/&gt;
  </code></pre>
  
  <p>I have to support API 14 and onwards.</p>
  
  <p>I do not want to go to the trouble of extending EditText for this one single case, therefore I am using am AccessibilityDelegate.</p>
  
  <pre><code>mEditTextView.setAccessibilityDelegate(accessibilityDelegate);
  </code></pre>
  
  <p>From the documentation I understand that in my delegate I only have to overwrite those methods in the delegate for which I would like to change the behaviour. All other methods will default to the View's implementation.  </p>
  
  <p><a href="http://developer.android.com/reference/android/view/View.AccessibilityDelegate.html" rel="noreferrer">http://developer.android.com/reference/android/view/View.AccessibilityDelegate.html</a>
  <a href="http://developer.android.com/reference/android/view/View.html" rel="noreferrer">http://developer.android.com/reference/android/view/View.html</a></p>
  
  <p>The doc for "onPopulateAccessibilityEvent" says : "<em>Gives a chance to the host View to populate the accessibility event with its text content.</em>" 
  The doc for "dispatchPopulateAccessibilityEvent" says : "<em>Dispatches an AccessibilityEvent to the host View first and then to its children for adding their text content to the event.</em>" and that the default behaviour is to call "onPopulateAccessibilityEvent" for the view itself and then "dispatchPopulateAccessibilityEvent" on all its children</p>
  
  <p><a href="http://developer.android.com/guide/topics/ui/accessibility/apps.html" rel="noreferrer">http://developer.android.com/guide/topics/ui/accessibility/apps.html</a></p>
  
  <p>This doc says under "onPopulateAccessibilityEvent" "*If your implementation of this event completely overrides the output text without allowing other parts of your layout to modify its content, then do not call the super implementation of this method in your code."</p>
  
  <p>Therefore my delegate is the following</p>
  
  <pre><code>View.AccessibilityDelegate accessibilityDelegate = new View.AccessibilityDelegate() {
      @Override
      public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
          event.getText().add("Apples");
      }
  
  };
  </code></pre>
  
  <p>Why when I use the keyboard to navigate to or use the screen to tap on the EditText view it is still reading "my hint text" and not "Apples"?</p>
  
  <p>If I use a debugger, I see that before I set the event text, the text is empty and after I set it, it is "Apples" yet the TalkBack still reads out the hint.</p>
  
  <hr>
  
  <p>Weirdly if I overwrite "onInitializeAccessibilityNodeInfo" and send an event with my desired text, then this desired text gets read out (see code snippet below). But this seems wrong to me as the "onInitializeAccessibilityNodeInfo" is reacting to the EditText's event but then just raising a new one.   </p>
  
  <pre><code>@Override  
  public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfo info){  
      super.onInitializeAccessibilityNodeInfo(v, info);      
      ...   
      final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);  
      event.getText().add("Pears");  
      event.setClassName(className);  
      event.setPackageName(packageName);  
      ...     
      v.getParent().requestSendAccessibilityEvent(v, event);  
  }
  </code></pre>