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

Time:09-27

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.

CodePudding user response:

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