Incorrect Focus Traversal Sequence

Id IncorrectFocusTraversalSequence
Summary The focus sequence does not follow the logical or visual layout of the interface
Severity N/A
Category Assistive Technologies / Focus and Navigation
Affects Resource files and Kotlin and Java files
Implementation AI or other solutions could be considered, since context is crucial, due to the need of understanding visual layout and logical user flow

Symptom

Screen reader navigation follows an illogical or unexpected sequence through UI elements, not matching conventional ordering patterns. (Solved by implementations like setAccessibilityTraversalAfter()).

Rationale

Creates confusion and cognitive burden for assistive technology users who cannot predict or efficiently navigate through content, forcing them to work against unexpected traversal patterns and potentially missing important information or functionality.

Examples

XML Layout Example

<!-- Elements that will be navigated in wrong visual order -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!-- Submit button appears first in accessibility order due to XML order -->
    <Button
        android:id="@+id/submit_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:text="Submit" />

    <!-- Name field should be first but comes after submit in XML -->
    <EditText
        android:id="@+id/name_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter your name" />

    <!-- Email field positioned between but wrong accessibility order -->
    <EditText
        android:id="@+id/email_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/name_field"
        android:hint="Enter your email" />

</RelativeLayout>

Kotlin Code Example

class WrongOrderActivity : AppCompatActivity() {

    private fun createFormWithWrongOrder() {
        val container = LinearLayout(this).apply {
            orientation = LinearLayout.VERTICAL
        }

        // Adding views in wrong accessibility order
        val submitButton = Button(this).apply {
            text = "Submit Form"
            // This gets added first, so it's focused first
        }

        val nameField = EditText(this).apply {
            hint = "Enter name"
            // Should be focused before submit button
        }

        val emailField = EditText(this).apply {
            hint = "Enter email"
            // Logical order: name → email → submit
        }

        // Wrong order: submit button gets focus before input fields
        container.addView(submitButton)
        container.addView(nameField)
        container.addView(emailField)

        // Missing: Proper accessibility traversal order setup
        // nameField.accessibilityTraversalAfter = View.NO_ID
        // emailField.accessibilityTraversalAfter = nameField.id
        // submitButton.accessibilityTraversalAfter = emailField.id
    }
}

GitHub issues under this tag