禁用的Andr​​oid AutoCompleteTextView后,用户从下拉选择项下移用户、Andr、oid、AutoCompleteTextView

2023-09-05 23:55:38 作者:败在主动

我使用的是Android的 AutoCompleteTextView 的CursorAdapter 添加自动完成功能的应用程序。在视图的 onItemClickListener()(即当用户触摸自动完成下拉项目之一),我检索的文本,并将其放置在EditText上,以便用户可以对它进行修改如果他们需要。

I'm using Android's AutoCompleteTextView with a CursorAdapter to add autocomplete to an app. In the view's onItemClickListener() (i.e. when the user touches one of the autocompleted drop down items) I retrieve the text and place it in the EditText so that the user can modify it if they need to.

然而,当我打电话的setText()在TextView的自动完成的行为被触发,下拉再次显示。我想只显示下拉如果使用键盘的用户类型的新文本。有没有办法做到这一点?

However, when I call setText() on the TextView the autocomplete behavior is triggered and the dropdown shows again. I'd like to only show the dropdown if the user types new text with the keyboard. Is there a way to do this?

推荐答案

黑客在此的几个小时后,回答我的问题:原来,你应该实现自己的 OnItemClickListener ,而是依赖于现有的点击监听器来填充的TextView。我原本实施的onItemClickListener,因为它是用Cursor.toString()的结果来填充文本视图。要改变输出字符串,你应该在你的CursorAdapter实施 convertToString(光标)。被返回的CharSequence的将被填充在文本视图。

Answering my own question after a couple hours of hacking at this: It turns out you should implement your own OnItemClickListener and instead rely on the existing click listener to populate the TextView. I had originally implemented the onItemClickListener because it was using the results of Cursor.toString() to populate the text view. To change the output String, you should implement convertToString(Cursor) in your CursorAdapter. The CharSequence that gets returned will be populated in the text view.

这样做也会prevent从显示再次下拉(自的setText()触发完成的行为,但默认onItemClickListener没有)。

Doing this will also prevent the dropdown from showing up again (since setText() triggers the completion behavior but the default onItemClickListener does not).