Android Question (solved) AutocompleteEditText help with list being dismissed

edm68

Member
Licensed User
Longtime User
Hi,

I need help with how to determine if an AutocompleteEditText dropdown has been dismissed without any item being clicked.

As an example:
I have an activity with 2 AutocompleteEditTexts. Both are set as INPUT_TYPE_NONE. Both are filled with SetItems(list).
The problem is that when the dropdown is shown, if the user doesn't click an item and clicks elsewhere, the dropdown closes, but the focus doesn't change. If the user then clicks on the sameAutocompleteEditText the dropdown doesn't show again. I was trying to handle this through the FocusChanged event, with no luck.
I did find this: https://developer.android.com/refer...idget.AutoCompleteTextView.OnDismissListener)
Not sure if that applies here and if I could use it though.

Thanks for any help.
 

edm68

Member
Licensed User
Longtime User
Why not use Spinner or B4XDialog with B4XListTemplate?
Hi, thanks for the reply.

I don't like spinner because: there's no hint text, as far as I know there's no way to force it to open, and there are times when the user may have to enter text. I was just using the above as an example.

I'm not familiar with B4XListTemplate, will look into it more. Although I don't think I need a dialog, it's something I would rather have on the main layout.

Thanks & Happy Holidays
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
as far as I know there's no way to force it to open
It is possible to open it programmatically: https://www.b4x.com/android/forum/t...l-down-the-spinners-lists.111072/#post-692855

Overall I tend to avoid using AutoCompleteEditText as there are nicer solutions such as this one: https://www.b4x.com/android/forum/threads/b4x-xui-minisearchview-autocomplete-field.93564/#content

However here is the code that you are looking for:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   AutoCompleteEditText1.SetItems(Array("aaa", "aab", "aac"))
   Dim jo As JavaObject = AutoCompleteEditText1
   Dim listener As Object = jo.CreateEventFromUI("android.widget.AutoCompleteTextView.OnDismissListener", "dismiss", Null)
   jo.RunMethod("setOnDismissListener", Array(listener))
End Sub

Sub Dismiss_Event (MethodName As String, Args() As Object) As Object
   If MethodName = "onDismiss" Then
       Log("dismissed")
   End If
   Return Null
End Sub
 
Upvote 0

edm68

Member
Licensed User
Longtime User
Thanks,
It works very well. I will look into the MiniSearchView option in the future.
Good to know about the force open of spinner also.
Thank you again.
 
Upvote 0
Top