Can you set custom content description for individual items in a dropdown list in Android?

Viewed 22

I was curious if there is a way to set the content description for each of the items in a drop down list? I'm using text input layout with Material Auto Complete Text View.

The reason is that I had a list of days but it's shortened and some devices don't say the whole day name when using talkback. For example I have "Tue", it should read Tuesday but it only reads "Tue". This is not true for all devices, for example pixel phones don't seem to have that issue.

1 Answers

You can implement your own Adapter and set necessary content description in a getView function, something like this:

class ContentDescriptionArrayAdapter(
    context: Context,
    resource: Int,
    items: Array<String>
) : ArrayAdapter<String>(context, resource, items) {

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = super.getView(position, convertView, parent)
        view.contentDescription = "YOUR CONTENT DESCRIPTION"
        return view
    }
}
Related