se22as se22as - 3 months ago 18
Android Question

How can i set the text which will be spoken when a value selected for an MultiAutoCompleteTextView

I have a custom view which extends from "MultiAutoCompleteTextView" . When the user starts typing in the CustomTextView a popup will show suggested values. On selecting one of these values, the CustomTextView is populated with the value selected.

The values which can be selected have IDs and Names. By default, when the user selects a value from the list and the CustomTextView is populated with that selected value TalkBack reads out the ID of the selected item in a strange way.

It reads


"(itemID as a whole word) replaces syn (itemId as individual charachers) comma space"


for example if the id was apple it reads


"apple replaces syn a p p l e comma space"


I would like it to just read out the name not the ID.

Reading the accessibility docs for adding custom views for accessibility (http://developer.android.com/guide/topics/ui/accessibility/apps.html#custom-views) I have tried overwriting the different APIs and setting the event text, but as soon as i do anything to the event text then nothing is read out.

I only have to support API 15 and above so in my CustomTextView I have added the code

public void onPopulateAccessibilityEvent(AccessibilityEvent event){
super.onPopulateAccessibilityEvent(event);
System.out.println("onPopulateAccessibilityEvent \n s = " + s
+ "\n event text = " + event.getText());

CharSequence c = "Test";
event.getText().clear();
event.getText().add(c);

System.out.println("event text after setting = " + event.getText());
}


I can see in my debugging system outs that the event text is getting updated to "Test" from the id

onPopulateAccessibilityEvent
s = Jo Blogs
event text = [UID1234, ]
event text after setting = [Test]


Therefore I do not understand why the string "Test" is not being read out loud? Any ideas?

Note: If I add the following code, then when the CustomTextView is touched on then "Touched on CustomTextView" is correctly read out. But having this method overwritten makes no difference to when an item is first selected from the suggestions and the CustomTextView is populated.

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
super.onInitializeAccessibilityNodeInfo(info);
info.setText("Touched on CustomTextView");
}

Answer
With the following accessibility methods overwritten this now seems to be working

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
    super.onInitializeAccessibilityNodeInfo(info);

    String s = getAccessibilityUsernameString();

    if (s != null && null != getAccessibilityUserNames()) {
        info.setText(s);
    }
}


@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    String s = getAccessibilityUsernameString();

    if (s != null) {
        event.getText().clear();
        event.getText().add(s);
    }
}   

where "getAccessibilityUserNames()" gets a string containing the names of the objects selected and "getAccessibilityUsernameString" returns a string "Selected items are %1$s"
Comments