Android Question How to initialize a view with Activity.GetView() ?

Philipp W

New Member
In my application want to load the layout again, after the user has "solved a riddle" (thats the content of my page). Since im filling lots of EditText fields in a loop at the beginning, im accessing them with Activity.GetView(x) in a loop.
When i do this the first time, this works. However, after removing all views and loading the same layout again, using Activity.GetView(x) causes the error

"Object should be initialized (View)"

Therefore i thought, i have to initialize all my 100 EditText fields again. Is this the case and can i do that with a loop?

Activity.GetView().Initialize does not exist, Activity.GetView().IsInitialized exists and returns false.



Im calling the following Sub in ActivityCreate

Private lbl As EditText is declared in Globals

Code:
Sub SetUpPage
    Activity.RemoveAllViews
    Activity.LoadLayout("Layout")
   
    For z=0 + riddle_number*11 To anz_zeilen - 1 + riddle_number*11
        For s=0 To 9
            If lbl.IsInitialized = False Then lbl.Initialize("lbl")
            'Log(Activity.GetView(z*Ordnung+s+(anz_felder+1)).IsInitialized)
            'Activity.GetView(0).Initialize ???
            lbl = Activity.GetView(z*Ordnung+s+(anz_felder+1))
            lbl.Text = Sheet1.GetCellValue(s,z).As(String) '(Text input comes from an Excel sheet)
        Next
    Next
   
    riddle_number = riddle_number + 1
End Sub


I assume, that after removing all views, the Views need to be initialized again. This seems not to happen in Activity.LoadLayout("Layout")


Best regards,


Philipp
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If lbl.IsInitialized = False Then lbl.Initialize("lbl")
This line makes no sense and should be removed.

When i do this the first time, this works. However, after removing all views and loading the same layout again, using Activity.GetView(x) causes the error
Loading the same layout works. The problem is somewhere else.
 
Upvote 0
Top