Android Question AutoComplete EditText not filling when inserted from Designer

BenF

Member
Licensed User
Longtime User
Hi All,
there may be a very simple solution to this that I am overlooking after staring at it for too long, so hopefully it's an easy fix. I have an Autocomplete Edittext that is inserted into a layout in the designer, which is supposed to be filled upon the opening of the layout with a list from a text file. When I try to set items from the text file, they don't seem to register. However, if (even though the ACET is inserted into the layout from the designer) I initialize the ACET and add it to the view, it works fine, with exactly the same input data (even though I thought Initializing a designer element was a no-no)... The problem with this is that it creates a second ACET, over the top of the one from the Designer.
B4X:
Sub Globals
    Dim PnlView As Panel
    Dim PnlViewSites As Panel
    Dim Btn_View_Sites As Button
    Dim DDL_ViewSites_Sites As AutoCompleteEditText
    Dim Site_List As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    PnlView.Initialize("")
    PnlView.LoadLayout("View")
    Activity.AddView(PnlView,0,0,100%x,100%y)
    PnlView.Visible = False

    PnlViewSites.Initialize("")
    PnlViewSites.LoadLayout("ViewSites")
    Activity.AddView(PnlViewSites,0,0,100%x,100%y)
    PnlViewSites.Visible = False
End Sub

Sub Btn_View_Sites_Click
    PnlView.Visible = False
    PnlViewSites.Visible = True
    Site_List = File.ReadList(File.DirInternal,"Site List.txt")
'    Msgbox(Site_List,"")
'    DDL_ViewSites_Sites.Initialize("")
    DDL_ViewSites_Sites.SetItems(File.ReadList(File.DirInternal,"Site List.txt"))
'    Activity.AddView(DDL_ViewSites_Sites,50dip,20dip,80%x,30%y)
End Sub

The text file is just a list of site names consisting of a code and a location, as a single string, one per line:
0001 (Site1 Location)
0002 (Site2 Location)
0003 (Site3 Location)

The only thing that I can think of is that the Declaration of the ACET in the code is not recognising the ACET from the designer for some reason, although I can't figure out why... all the naming seems consistent between them, unless I'm going blind. I've attached a screenshot of the designer, showing the layout and ACET properties.
Any help with this would be greatly appreciated, I'm hoping it's something incredibly simple that I've overlooked...

Cheers,
Ben
 

Attachments

  • Basic4android image.JPG
    Basic4android image.JPG
    142.3 KB · Views: 380

BenF

Member
Licensed User
Longtime User
Hi Erel,
Thanks for taking a look, much appreciated.

Cheers,
Ben
 

Attachments

  • Sample_Submission_BenF.zip
    49.4 KB · Views: 224
Upvote 0

BenF

Member
Licensed User
Longtime User
The ACET that is causing me problems is DDL_ViewSites_Sites. It is declared in the ViewSites layout. It is supposed to read from the file 'site list.txt', in DirInternal. The in app access to the problematic panel is (from the main menu) 'View Previous Data' -> 'View Site List'.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you run it in debug mode you will see many warnings like: (Main, 250) Panel.LoadLayout should only be called after the panel was added to its parent. (warning #1001)

You should first add the panels to the activity and then load the layout.

It is usually better to use a different activity for each layout. In this case the problem is that there is another DDL_ViewSites_Sites in ViewProjects.

I found it by checking the value of this variable BEFORE the layout is loaded. It should have been Not Initialized:

SS-2014-06-17_08.40.51.png


Then I run it step by step to see where it is loaded.
 
Upvote 0

BenF

Member
Licensed User
Longtime User
Many Thanks Erel! I guess these are the risks of barrelling ahead without working through the tutorials... :S I'll work back through it using the debugger to try and catch any more things that have slipped through the cracks!

Cheers, Ben.
 
Upvote 0
Top