Android Question tabstripviewerpage, using same layout only the last page labels are updated

jimseng

Active Member
Licensed User
Longtime User
Hello.
I am trying the tabstripviewerpage. I have a layout with 4 seek bars and 4 labels. The seekbar updates the label with the seekbar value. I was hoping to be able to load the same layout on 4 tabs but when using the seekbars only the last tab labels get updated. I am obviously missing something fundamental. Do I need to create 4 layouts with individual views for each tab or is there a better way?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do I need to create 4 layouts with individual views for each tab or is there a better way?
Of course not. There are many better ways. I like to use DDD: https://www.b4x.com/android/forum/threads/b4x-dse-designer-script-extensions.141312/#content

1758172996079.png


I've added a B4XSeekBar to make it a vertical var, otherwise it conflicts with the pages switching gesture.

Complete code:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private dd As DDD
    Private TabStrip1 As TabStrip
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    dd.Initialize
    xui.RegisterDesignerClass(dd)
    For i = 1 To 5
        TabStrip1.LoadLayout("Tab", "Page " & i)
    Next
End Sub

Private Sub B4XSeekBar1_ValueChanged (Value As Int)
    Dim Seekbar As B4XSeekBar = Sender
    'The layout data is stored in the view that layout was loaded to - the parent of the B4XSeekBar, which is accessed through the base panel.
    'Note the call to ddd.CollectViewsData in the Tab layout designer script.
    Dim label As B4XView = dd.GetViewByName(Seekbar.mBase.Parent, "Label1")
    label.Text = "Value " & Seekbar.Value
End Sub
 

Attachments

  • 2.zip
    15.1 KB · Views: 14
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
Thanks Erel, this is much better.
Can I access the seekbar programmatically? i.e. can I set its value from code (for instance when the tab is shown). I am struggling with that.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The TabStrip makes it a bit mode difficult. You can use this code:
B4X:
Private Sub Button1_Click
    Dim PageRoot As B4XView = GetRootPanel(TabStrip1, TabStrip1.CurrentPage)
    Dim seekbar As B4XSeekBar = dd.GetViewByName(PageRoot, "B4XSeekBar1").Tag 'tag is needed because it is a custom view (https://www.b4x.com/android/forum/threads/117992/#content)
    seekbar.Value = Rnd(0, 100)
End Sub

Private Sub GetRootPanel(TabStrip As TabStrip, PageIndex As Int) As B4XView
    Return TabStrip.As(JavaObject).GetFieldJO("pages").RunMethod("get", Array(PageIndex))
End Sub
 
Upvote 0
Top