TalkBack でカスタム メッセージを読み上げさせるために、dispatchAccessibilityEvent() をオーバーライドする方法のテンプレートとして、Google UserRowView クラスを使用しました。
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;
}
リスト項目のレイアウトは次のとおりです。
<?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>
ListView のアダプターの getView() メソッドでテキストを設定します。
問題は、リスト項目がフォーカスされているときに TalkBack が読み上げるテキストを変更しないことです。
上記のレイアウトでは、設定したテキストを読み上げたいときに、3 つの TextView のテキストが読み上げられます。どうすればこれを実現できますか?