如何使用自定义适配器从AutoCompleteTextView获取所选项目
因此,我有一个自定义适配器,它基本上是加载图标和文本,导致以下视图:
现在,每当我选择其中一个项目时,都会发生两个问题:
- 图标确实会发生:未在AutoCompleteTextView的内部显示。
- 文字显示内部,但我无法再次更改它...如果我单击那个小箭头以再次打开列表,则它不会打开。
我只有在添加以下代码时才能得到这种行为:
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:
Now the probem is, that whenever I select one of these items, two problems occur:
- The icon does not show inside of the autoCompleteTextView.
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法弄清了这两个问题的问题。
显然,该过滤器默认设置为“ setText”上的true,因此应该将其设置为false,这就是为什么列表第二次未显示任何项目的原因:
对于我必须为TextInputlayout设置的图标,自动完成。
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:
As for the icon I had to set it for the TextInputLayout instead of the autoComplete.