Android Question Accessing views in current page of tabstrip [SOLVED]

JCO

Active Member
Licensed User
Longtime User
Hello,

I'm using the tabstrip to load many times the same layout. The views in each tab are filled with different data in code in Activity_Create
- tsMain is the tabstrip view
- The views in the layout are declared in the activity's code
- Sub ShowRecord fills the views in the page with the current record in the cursor
- This part works fine :)

B4X:
    query = "SELECT * FROM people "
  
    cr = Starter.sql1.ExecQuery(query & Starter.applyFilter & " LIMIT 10")
    For i = 0 To cr.RowCount - 1
        cr.Position = i
        tsMain.LoadLayout("ItemView", "")
        ShowRecord(cr)
    Next

I'd like to change a view's (textedit) text in the active tab when an action is performed, but when I do, the view that changes is the one in the last loaded page.
My question is: Can i access the views in the current tab?

Many thanks,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The global variables will reference the views of the last loaded layout.
This means that you need to manage the references yourself. There are all kinds of ways to do it.

The right place to do it is right after you call LoadLayout as at that point the variables will point to the correct views.

Lets say that you want to access EditText1 and Button1.
B4X:
Sub Globals
 Private ImportantViews As List
 Private EditText1 As EditText
 Private Button1 As Button
End SUb

Sub Activity_Create (FirstTime As Boolean)
 ImportantViews.Initialize
 '...

End Sub

tsMain.LoadLayout("", "")
ImportantViews.Add(CreateMap("EditText1": EditText1, "Button1": Button1))

'Access views of page n:
Dim m As Map  ImportantViews.Get(n)
Dim et As EditText = m.Get("EditText1")
et.Text = "abc"
 
Upvote 0
Top