Android Question B4XPlusMinus on ScrollView

Mario Krsnic

Member
Licensed User
Hello everybody,
I try to use custom controlls on the ScrollView.
1) I load the layouts with b4xplusminus controls,
2) I make the array of the controls and with panels with the code:
B4X:
Mood = Array As B4XPlusMinus (B4XPlusMinus1, B4XPlusMinus2, B4XPlusMinus3,B4XPlusMinus4)
pan = Array As Panel (Pan1, Pan2, Pan3,Pan4)
3) then I try to fill the scrollview:
B4X:
ScrollView1.Panel.AddView(pan(i), 2dip,  i* 120dip +35dip , 300dip, 30dip)
        
            Mood(i).SetNumericRange(0, 10, 1)
            Mood(i).SelectedValue=0
            Mood(i).Tag = i +1

But it does not work properly. Please help me!
Here is the whole code:
B4X:
#Region  Project Attributes
    #ApplicationLabel:  test
    #VersionCode: 1
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private DobaDana() As String
 
    DobaDana = Array As String("Last night","Morning", "Afternoon", "Evening" )
    
    Private lbl(4) As Label

 
    Private i As Int
    'Private StimmPlMin(4) As B4XPlusMinus
    Private ScrollView1 As ScrollView
 
 
    
    Private Mood(4) As B4XPlusMinus
    Private pan(4) As Panel
    
    Private B4XPlusMinus1 As B4XPlusMinus
    Private B4XPlusMinus2 As B4XPlusMinus
    Private B4XPlusMinus3 As B4XPlusMinus
    Private B4XPlusMinus4 As B4XPlusMinus
    
    Private Pan1 As Panel
    Private Pan2 As Panel
    Private Pan3 As Panel
    Private Pan4 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("plusminus1")
    Activity.LoadLayout("plusminus2")
    Activity.LoadLayout("plusminus3")
    Activity.LoadLayout("plusminus4")
    'is it reasonably to load layout and remove all views, to be ably to use custom controlls??
    Activity.RemoveAllViews
    
    Activity.LoadLayout("Stimmungstagebuch")

    Activity.Title="Mood diary"
    
    Mood = Array As B4XPlusMinus (B4XPlusMinus1, B4XPlusMinus2, B4XPlusMinus3,B4XPlusMinus4)
    pan = Array As Panel (Pan1, Pan2, Pan3,Pan4)
 
    FillScrollView
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub FillScrollView

    Try
        
        For i=0 To 3
            'HERE IS EVERYTHING OK.
            
            lbl(i).Initialize ("lbl")
            lbl(i).TextColor = Colors.Black
            lbl(i).Gravity=Gravity.CENTER_HORIZONTAL
            lbl(i).Text =DobaDana(i)
        
            ScrollView1.Panel.AddView(lbl(i), 2,  i* 120dip  , 100%x, 30dip)
        
         'HERE THERE ARE PROBLEMS:
            ScrollView1.Panel.AddView(pan(i), 2dip,  i* 120dip +35dip , 300dip, 30dip)
        
            Mood(i).SetNumericRange(0, 10, 1)
            Mood(i).SelectedValue=0
            Mood(i).Tag = i +1
            
        Next
        
    Catch LastException
        MsgboxAsync ( LastException.Message,"Fehler"  )
    End Try
End Sub
I attached the zip-file as well!
Thanks!
Mario
 

Attachments

  • test.zip
    101.6 KB · Views: 285

Mario Krsnic

Member
Licensed User
It happens that only the second and third plusminus-controll loads and the first and last one not. As you can see on the screenshot.
Ok, now I will try with xCLV, thanks Erel.
 

Attachments

  • mood.jpg
    mood.jpg
    13.2 KB · Views: 257
Upvote 0

Mahares

Expert
Licensed User
Longtime User
now I will try with xCLV
If is a good idea to use xCLV as Erel suggested. Here is an almost complete project code using xCLV if you are switching to xCLV or need a push.
B4X:
Sub Globals
    Private xui As XUI
    Private CustomListView1 As CustomListView
    Private Label1 As Label
    Private B4XPlusMinus1 As B4XPlusMinus
    Private MyList As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("laymain")  'has CustomListView1
    MyList.Initialize
    MyList.AddAll(Array ("Last night","Morning", "Afternoon", "Evening" ))
    PopulateCLV
End Sub

Sub PopulateCLV
    For i = 0 To MyList.Size - 1
        CustomListView1.Add(CreateMyItems(MyList.Get(i)),i)        
    Next
End Sub

Sub CreateMyItems(s As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,CustomListView1.AsView.Width,100dip)
    p.LoadLayout("Item")  'has Label1 and B4XPlusMinus1
    B4XPlusMinus1.SetNumericRange(0, 10, 1)
    B4XPlusMinus1.SelectedValue=0
    Label1.Text= s
    Return p
End Sub
 
Upvote 0

Mario Krsnic

Member
Licensed User
Yes, I want to switch, but I need a push, as you said. Thank you so much, Mahares! :)
I have tested your code and it is a perfect solution for my problem! Hurrah!
 
Upvote 0
Top