Android Question Behavior of AutoCompleteEditText

LucaMs

Expert
Licensed User
Longtime User
I'm trying to create a custom view, a mix between Spinner and AutoCompleteEditText.
(It should also allow the user to add items and returns an object).

I would like to avoid strange behavior of AutoCompleteEditText.

I try to explain (difficult!).

If the user selects an item (ITEM_CLICK) the AutoCompleteEditText.Text is filled with the selected text and the cursor is on the right of the text.
If, at this point, I use the command "ShowDropDown" to show the list (the user presses the button with the classic inverted triangle), the list is regularly and fully displayed.

If, however, the code sets the text of AutoCompleteEditText, text that is an item of the list (added by the user), the command ShowDropDown shows only that item.

If you launch the app (preferably step by step) and read the few comments, you will understand better.


Thank you in advance, although I fear that the solution is difficult.
 

Attachments

  • LM_Spinner.zip
    17.8 KB · Views: 325
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that this comment is incorrect:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
   ' Attention: UserClosed will be True even if orientation changes.
End Sub
UserClosed will be false then the orientation changes.

If, at this point, I use the command "ShowDropDown" to show the list (the user presses the button with the classic inverted triangle), the list is regularly and fully displayed.
I don't see this behavior.
I selected uno from the list and then pressed on the arrow:

upload_2014-4-16_8-3-49.png


Only the matching item appears.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
As you know, the comment is "automatic", but thanks for pointing this out, for now I use only the Portrait and then I did not realize.

I explained myself badly, most likely. That is the unwanted behavior.

When you select an item from the list, instead of adding a new item, and then you press "Open", the complete list is displayed and this is right.

(I thought of using a listview, only when the user presses the "Open", but I do not think that I can show it, right?)


Thank you for your answer and for your time, Erel.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I am afraid that there is not a solution (not everything is possible!).

But I want to have the satisfaction of being able to explain what I mean :D

When I show the list via the ShowDropDown command and the user selects an item, this item "passes" into the AutoCompleteEditText.Text, then the list closes.
Reopening the list, it shows all items, not just those that begin with the same characters (ie not only the selected "Edit" and "EditText" but all the items) and this is the correct behavior.

Instead, when I write in the code: AutoCompleteEditText.Text = "Edit" because the user has added the item "Edit" (by pressing the Add button (+)), at that point, opening the list again using the command ShowDropDown, the list will only display the "Edit" and "EditText".

---

One way to overcome this would be the use of a Listview, as in your class. But in your class SearchView you use AddToParent to "create" the view, getting the Parent object (Activity or Panel) from it.
I will not be able to add a Listview because the custom view must be adapted for the designer, and then I will not have the Parent object.

---

I searched for a way to get the "container" for a view.
I found this but I do not know if it is possible to do something via Reflection.



Thanks again for your help, Erel.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub GetParent(v As View) As View
    Dim r As Reflector
    r.Target = v
    Return r.RunMethod("getParent")
End Sub

?

No, I think I have already done this test some time ago.
I should use "Me" (as parameter) but "Me" is not a view
 
Upvote 0
Top