I’ve used the Google UserRowView class as a template of how to override dispatchAccessibilityEvent() in order to have TalkBack speak a custom message:
public class UserRowView extends LinearLayout {
.
.
public void setText(String text)
_message = text;
}
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent accessEvent) {
Context ctx = this.getContext();
accessEvent.setClassName(getClass().getName());
accessEvent.setPackageName(ctx.getPackageName());
accessEvent.getText().clear();
accessEvent.getText().add(_message);
return true;
}
The list item layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="@color/all_white">
<ImageView
android:id="@+id/catalog_entry_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/member_active" />
<com.topiatechnology.skoot.android.util.UserRowView
android:id="@+id/catalog_entry_user_row_view"
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
>
<TextView
android:id="@+id/catalog_entry_name_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/catalog_entry_size_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/catalog_entry_date_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:id="@+id/catalog_entry_progress_bar"
android:visibility="gone"
/>
</com.topiatechnology.skoot.android.util.UserRowView>
</LinearLayout>
I set the text in my getView() method in the ListView’s adapter.
The problem is that TalkBack does not change the text it speaks when a list item is focused on.
For the layout above, the text of the three TextViews is spoken while I want the text I set to be spoken. How can I make this happen?
Use View.setContentDescription() to set a content description on the layout containing the views that you don’t want read aloud. TalkBack will read the content description and ignore the text of the child views.
In general, setting the AccessibilityEvent text to control feedback from focus and selection is no longer recommended.