如何使用自定义适配器从AutoCompleteTextView获取所选项目

发布于 2025-02-05 02:16:27 字数 853 浏览 3 评论 0原文

因此,我有一个自定义适配器,它基本上是加载图标和文本,导致以下视图:

“在此处输入图像描述”

现在,每当我选择其中一个项目时,都会发生两个问题:

  1. 图标确实会发生:未在AutoCompleteTextView的内部显示。
  2. 文字显示内部,但我无法再次更改它...如果我单击那个小箭头以再次打开列表,则它不会打开。

我只有在添加以下代码时才能得到这种行为:

      exchangeBinding.autoCompleteTextView.setOnItemClickListener(OnItemClickListener { parent, view, position, id ->
        val item = parent.getItemAtPosition(position)
        if (item is PaymentMethod) {
            exchangeBinding.autoCompleteTextView.setText(item.paymentMethodName)
            exchangeBinding.autoCompleteTextView.setCompoundDrawablesWithIntrinsicBounds(item.paymentMethodIcon, 0, 0,0)
        
        }
    })

So I have a custom Adapter which basically loads an icon and a text, resulting into the following view:

enter image description here

Now the probem is, that whenever I select one of these items, two problems occur:

  1. The icon does not show inside of the autoCompleteTextView.
  2. The text shows inside, but I'm unable to change it again...if I click that little arrow to open the list again, it just doesn't open.

I only get that behavior when I add the following code:

      exchangeBinding.autoCompleteTextView.setOnItemClickListener(OnItemClickListener { parent, view, position, id ->
        val item = parent.getItemAtPosition(position)
        if (item is PaymentMethod) {
            exchangeBinding.autoCompleteTextView.setText(item.paymentMethodName)
            exchangeBinding.autoCompleteTextView.setCompoundDrawablesWithIntrinsicBounds(item.paymentMethodIcon, 0, 0,0)
        
        }
    })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声 2025-02-12 02:16:27

我设法弄清了这两个问题的问题。

显然,该过滤器默认设置为“ setText”上的true,因此应该将其设置为false,这就是为什么列表第二次未显示任何项目的原因:

 exchangeBinding.autoCompleteTextView.setText(item.paymentMethodName, false)

对于我必须为TextInputlayout设置的图标,自动完成。

exchangeBinding.textInputLayoutDropDown.startIconDrawable = drawable

I managed to figure out the problem for both issues.

Apparently, the filter is set to true by default on "setText", so it should be set to false instead and that's why the list was not showing any items the second time:

 exchangeBinding.autoCompleteTextView.setText(item.paymentMethodName, false)

As for the icon I had to set it for the TextInputLayout instead of the autoComplete.

exchangeBinding.textInputLayoutDropDown.startIconDrawable = drawable
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文