简体   繁体   English

Android ListView标头可访问性问题

[英]Android listview header accessibility issue

When using a android listview header with accessibility (google talkback) the entire contents of the header are read. 当使用具有辅助功能的android listview标头(Google对讲)时,标头的全部内容都会被读取。 So imagine i had a header view like this: 因此,想象一下我有这样的标题视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LinearLayout" >

<Button
    android:text="BUTTON"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text 1"
    android:paddingTop="10px"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text 2"
    android:paddingTop="10px"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text 3"
    android:paddingTop="10px"/>

Whenever i click anything in the header ALL the textview titles get announced. 每当我单击标题中的所有内容时,所有textview标题都会被宣布。 so in this case if i click text 3, the system announces "TEXT 1, TEXT 2, TEXT 3". 因此,在这种情况下,如果我单击文本3,系统会宣布“ TEXT 1,TEXT 2,TEXT 3”。 it's automatic. 它是自动的。 How do i get it to not announce all the things just the item the user clicks on ? 我如何才能不宣布用户单击的项目而仅宣布所有内容?

here is my listview code, its just standard stuff: 这是我的listview代码,它只是标准的东西:

public class MainActivity extends Activity {
    ListView listView ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);

        // Get ListView object from xml
        listView = (ListView) findViewById(R.id.list);

        // Defined Array values to show in ListView
        String[] values = new String[] { "Android List View",
                "Adapter implementation",
                "Simple List View In Android",
                "Create List View Android",
                "Android Example",
                "List View Source Code",
                "List View Array Adapter",
                "Android Example List View"
        };

        // Define a new Adapter
        // First parameter - Context
        // Second parameter - Layout for the row
        // Third parameter - ID of the TextView to which the data is written
        // Forth - the Array of data

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);


        View header = getLayoutInflater().inflate(R.layout.header, null);


        listView.addHeaderView(header);

        // Assign adapter to ListView
        listView.setAdapter(adapter);

        // ListView Item Click Listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                // ListView Clicked item index
                int itemPosition     = position;

                // ListView Clicked item value
                String  itemValue    = (String) listView.getItemAtPosition(position);

                // Show Alert
                Toast.makeText(getApplicationContext(),
                        "Position :" + itemPosition + "  ListItem : " + itemValue, Toast.LENGTH_LONG)
                        .show();

            }

        });
    }

}

在我的headerView根目录中,我在api 16中设置了以下命令,主要用于纠正此问题:

android:importantForAccessibility="no"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM