Android Question CLV + TabStrip + CheckBox. Strange bug.

red30

Well-Known Member
Licensed User
Longtime User
I am using TabStrip. Each page contains a CustomListView. Each CustomListView contains 5 CheckBoxes. If I call a subroutine in the Starter that calls a subroutine in the Main Activity, then on the second and subsequent pages of the TabStrip the checkbox for the CheckBox is not displayed. Moreover, the frame is highlighted as if CheckBox Checked, but there is no check mark itself.
First TabStrip page:
Screenshot_20211029-120153.png
Second TabStrip page:
Screenshot_20211029-120158.png
Why it happens? How to solve this problem?
Program code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

#AdditionalJar: com.android.support:support-v4

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

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private CheckBox1 As CheckBox
    Private CheckBox2 As CheckBox
    Private CheckBox3 As CheckBox
    Private CheckBox4 As CheckBox
    Private CheckBox5 As CheckBox
    Private CheckBox11 As CheckBox
    Private CheckBox21 As CheckBox
    Private CheckBox31 As CheckBox
    Private CheckBox41 As CheckBox
    Private CheckBox51 As CheckBox
    Private CheckBox12 As CheckBox
    Private CheckBox22 As CheckBox
    Private CheckBox32 As CheckBox
    Private CheckBox42 As CheckBox
    Private CheckBox52 As CheckBox
    Private CheckBox13 As CheckBox
    Private CheckBox23 As CheckBox
    Private CheckBox33 As CheckBox
    Private CheckBox43 As CheckBox
    Private CheckBox53 As CheckBox
    Private TabStrip1 As TabStrip
    Private clv1 As CustomListView
    Private clv2 As CustomListView
    Private clv3 As CustomListView
    Private clv4 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Activity.TitleColor=Colors.White
    TabStrip1.LoadLayout("c1", "КАНАЛ 1")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clv1.AsView.Width, (Activity.Height*1.45)+50)
    p.LoadLayout("1")
    clv1.Add(p,"")
    TabStrip1.LoadLayout("c2", "КАНАЛ 2")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clv2.AsView.Width, (Activity.Height*1.45)+50)
    p.LoadLayout("2")
    clv2.Add(p,"")
    TabStrip1.LoadLayout("c3", "КАНАЛ 3")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clv3.AsView.Width, (Activity.Height*1.45)+50)
    p.LoadLayout("3")
    clv3.Add(p,"")
    TabStrip1.LoadLayout("c4", "КАНАЛ 4")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clv4.AsView.Width, (Activity.Height*1.45)+50)
    p.LoadLayout("4")
    clv4.Add(p,"")
   
    CallSubDelayed(Starter,"gostarter")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub AllCheck
    CheckBox1.Checked=True
    CheckBox2.Checked=True
    CheckBox3.Checked=True
    CheckBox4.Checked=True
    CheckBox5.Checked=True
   
    CheckBox11.Checked=True
    CheckBox21.Checked=True
    CheckBox31.Checked=True
    CheckBox41.Checked=True
    CheckBox51.Checked=True
   
    CheckBox12.Checked=True
    CheckBox22.Checked=True
    CheckBox32.Checked=True
    CheckBox42.Checked=True
    CheckBox52.Checked=True
   
    CheckBox13.Checked=True
    CheckBox23.Checked=True
    CheckBox33.Checked=True
    CheckBox43.Checked=True
    CheckBox53.Checked=True
End Sub
I tried the same code on another device and there are check marks on the first and second page, but not on the third and fourth.
 

Attachments

  • testliana.zip
    19.3 KB · Views: 232
Last edited:

Mahares

Expert
Licensed User
Longtime User
How to solve this problem?
If your top goal is to have all boxes checked, all I did is remove or comment the gostarter sub from the starter service, removed the call in main activity: CallSubDelayed(Starter,"gostarter"). Replaced it with a call to AllCheck, at the end of Activity_Create and all checkboxes are checked in all pages..
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i confirm that there is a problem with TabStrip. i also get the same behavior.
i do need to mention that your code is not very efficient but it should work.

if you decide to work with CustomListView then it make sense to have item in the clv (Custom"ListView")
instead what you do is create a big panel with many checkboxes ordered like items and load it to the clv. like this, you could just use the panel if you don't want to have multiple items.

you should have a look at arrays and Sender Object.

I re-wrote your code to make it more clear but I also get the same behavior. strange :confused:
i also try to use Sleep() or forced to redraw the checkbox with checkbox.invalidate() but again same behavior.

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

#AdditionalJar: com.android.support:support-v4

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

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private TabStrip1 As TabStrip
    Private clv1, clv2, clv3, clv4 As CustomListView
    Private clv(4) As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Activity.TitleColor = Colors.White
    
    TabStrip1.LoadLayout("1", "PAGE 1")
    TabStrip1.LoadLayout("2", "PAGE 2")
    TabStrip1.LoadLayout("3", "PAGE 3")
    TabStrip1.LoadLayout("4", "PAGE 4")
    
    fillclvs
End Sub

Sub fillclvs
    'reference panels to array
    clv(0) = clv1
    clv(1) = clv2
    clv(2) = clv3
    clv(3) = clv4
    
    For i = 0 To 3
        For j = 0 To 9
            clv(i).Add(CreateItem(j,100%x,7.5%y),j)
        Next
    Next
End Sub

Sub TabStrip1_PageSelected (Position As Int)
    Log(Position)
End Sub

Private Sub CreateItem(value As Object, width As Float, height As Float) As B4XView
    Dim p As B4XView = xui.CreatePanel("clvItem")
    p.Width = width
    p.Height = height
    p.Tag = value
    
    Dim chk As CheckBox
    chk.Initialize("chk")
    chk.Checked = False
    chk.Text = $"CheckBox: ${value.As(Int)}"$
    chk.Tag = value
    
    p.AddView(chk,0,0,width*0.5, height)
    Return p
End Sub

Sub clvItem_Click
    Dim p As B4XView = Sender
    Log($"You clicked Item ${p.Tag}"$)
End Sub

Sub chk_CheckedChange(Checked As Boolean)
    Log($"You checked the CheckBox"$)
End Sub
 
Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub AllCheck
    For i = 0 To clv.Length-1
        For j = 0 To clv(i).Size-1
            Dim p As B4XView = clv(i).GetPanel(j)
            Dim chk As CheckBox = p.GetView(0)
            chk.Checked = True
        Next
    Next
End Sub

Private Sub Button1_Click
    AllCheck
    ToastMessageShow("All checkbox are checked!",False)
End Sub
 

Attachments

  • testliana.zip
    8.7 KB · Views: 242
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
If your top goal is to have all boxes checked, all I did is remove or comment the gostarter sub from the starter service, removed the call in main activity: CallSubDelayed(Starter,"gostarter"). Replaced it with a call to AllCheck, at the end of Activity_Create and all checkboxes are checked in all pages..
I understand it. This is just a test program to showcase this bug.
i confirm that there is a problem with TabStrip. i also get the same behavior.
i do need to mention that your code is not very efficient but it should work.

if you decide to work with CustomListView then it make sense to have item in the clv (Custom"ListView")
instead what you do is create a big panel with many checkboxes ordered like items and load it to the clv. like this, you could just use the panel if you don't want to have multiple items.

you should have a look at arrays and Sender Object.

I re-wrote your code to make it more clear but I also get the same behavior. strange :confused:
i also try to use Sleep() or forced to redraw the checkbox with checkbox.invalidate() but again same behavior.

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

#AdditionalJar: com.android.support:support-v4

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

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private TabStrip1 As TabStrip
    Private clv1, clv2, clv3, clv4 As CustomListView
    Private clv(4) As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Activity.TitleColor = Colors.White
  
    TabStrip1.LoadLayout("1", "PAGE 1")
    TabStrip1.LoadLayout("2", "PAGE 2")
    TabStrip1.LoadLayout("3", "PAGE 3")
    TabStrip1.LoadLayout("4", "PAGE 4")
  
    fillclvs
End Sub

Sub fillclvs
    'reference panels to array
    clv(0) = clv1
    clv(1) = clv2
    clv(2) = clv3
    clv(3) = clv4
  
    For i = 0 To 3
        For j = 0 To 9
            clv(i).Add(CreateItem(j,100%x,7.5%y),j)
        Next
    Next
End Sub

Sub TabStrip1_PageSelected (Position As Int)
    Log(Position)
End Sub

Private Sub CreateItem(value As Object, width As Float, height As Float) As B4XView
    Dim p As B4XView = xui.CreatePanel("clvItem")
    p.Width = width
    p.Height = height
    p.Tag = value
  
    Dim chk As CheckBox
    chk.Initialize("chk")
    chk.Checked = False
    chk.Text = $"CheckBox: ${value.As(Int)}"$
    chk.Tag = value
  
    p.AddView(chk,0,0,width*0.5, height)
    Return p
End Sub

Sub clvItem_Click
    Dim p As B4XView = Sender
    Log($"You clicked Item ${p.Tag}"$)
End Sub

Sub chk_CheckedChange(Checked As Boolean)
    Log($"You checked the CheckBox"$)
End Sub
 
Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub AllCheck
    For i = 0 To clv.Length-1
        For j = 0 To clv(i).Size-1
            Dim p As B4XView = clv(i).GetPanel(j)
            Dim chk As CheckBox = p.GetView(0)
            chk.Checked = True
        Next
    Next
End Sub

Private Sub Button1_Click
    AllCheck
    ToastMessageShow("All checkbox are checked!",False)
End Sub
Yes, my code was hastily written just to demonstrate this bug. Yes, I confirm that your code works the same: there are no checkmarks on the CheckBox part.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This is just a test program to showcase this bug.
I don't think there is a bug. Here are the changes you need to make to the project in post #3 to make it work:
B4X:
Sub fillclvs
    'reference panels to array
    clv(0) = clv1
    clv(1) = clv2
    clv(2) = clv3
    clv(3) = clv4
     
    For i = 0 To 3
        For j = 0 To 9
            clv(i).Add(CreateItem(j,100%x,7.5%y),j)
        Next
    Next    
    AllCheck(0)
End Sub

Sub TabStrip1_PageSelected (Position As Int)
    AllCheck(Position)
End Sub

Sub AllCheck(myposition As Int)
        For j = 0 To clv(myposition).Size-1
            Dim p As B4XView = clv(myposition).GetPanel(j)
            p.GetView(0).Checked=True
        Next
End Sub

You no longer need the Button1_click sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I don't think there is a bug. Here are the changes you need to make to the project in post #3 to make it work:
B4X:
Sub fillclvs
    'reference panels to array
    clv(0) = clv1
    clv(1) = clv2
    clv(2) = clv3
    clv(3) = clv4
    
    For i = 0 To 3
        For j = 0 To 9
            clv(i).Add(CreateItem(j,100%x,7.5%y),j)
        Next
    Next   
    AllCheck(0)
End Sub

Sub TabStrip1_PageSelected (Position As Int)
    AllCheck(Position)
End Sub

Sub AllCheck(myposition As Int)
        For j = 0 To clv(myposition).Size-1
            Dim p As B4XView = clv(myposition).GetPanel(j)
            p.GetView(0).Checked=True
        Next
End Sub

You no longer need the Button1_click sub

the button click just calls the AllCheck event.
the problem here is not how to make all checkboxes get selected. the problem here is that the checkbox is checked but you cannot see the check sign in it only on some checkboxes. if you see closely you can see that the border has changed color but the inside of the checkbox is not drawn.

something is wrong.
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I don't think there is a bug. Here are the changes you need to make to the project in post #3 to make it work:
B4X:
Sub fillclvs
    'reference panels to array
    clv(0) = clv1
    clv(1) = clv2
    clv(2) = clv3
    clv(3) = clv4
  
    For i = 0 To 3
        For j = 0 To 9
            clv(i).Add(CreateItem(j,100%x,7.5%y),j)
        Next
    Next 
    AllCheck(0)
End Sub

Sub TabStrip1_PageSelected (Position As Int)
    AllCheck(Position)
End Sub

Sub AllCheck(myposition As Int)
        For j = 0 To clv(myposition).Size-1
            Dim p As B4XView = clv(myposition).GetPanel(j)
            p.GetView(0).Checked=True
        Next
End Sub

You no longer need the Button1_click sub
The project in post # 3 already works, no need to change anything! The problem is that if you click the "Check All" button, the checkboxes are not set on all TabStrip pages. To make it even clearer, look at the screenshots:
Screenshots of all TabStrip pages before clicking the Check All button:
Screenshot_20211030-170742.pngScreenshot_20211030-170747.pngScreenshot_20211030-170752.pngScreenshot_20211030-170757.png
Screenshots of all pages after clicking the Check All button:
Screenshot_20211030-170832.pngScreenshot_20211030-170836.pngScreenshot_20211030-170841.pngScreenshot_20211030-170844.png
Here we see that there are no checkmarks on the third and fourth pages. And if you look closely, the frame is painted in the desired color, there is simply no checkmark in the checkbox.

the button click just calls the AllCheck event.
the problem here is not how to make all checkboxes get selected. the problem here is that the checkbox is checked but you cannot see the check sign in it only on some checkboxes. if you see closely you can see that the border has changed color but the inside of the checkbox is not drawn.

something is wrong.
Yes you are right! Above, I posted screenshots to make it even clearer.

ilan, if you change your example and add RadioButton instead of CheckBox, then the effect is the same. Only the first two pages have dots, and the subsequent ones don't.
Screenshot_20211030-172229.pngScreenshot_20211030-172238.pngScreenshot_20211030-172248.pngScreenshot_20211030-172252.png
I think this is some kind of TabStrip error, but I don't understand how to fix it ... Because of this error, I cannot use the TabStrip. Is there any alternative to TabStrip?
Or maybe someone has some solutions to this error?
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
I cannot use the TabStrip. Is there any alternative to TabStrip?
what are you trying to archive what kind of app?
i never use tabstrip in my apps. i find tabstrip more suitable for desktop applications, not for mobile.


why did you choose tabstrip? what app do you want to make?
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
what are you trying to archive what kind of app?
i never use tabstrip in my apps. i find tabstrip more suitable for desktop applications, not for mobile.


why did you choose tabstrip? what app do you want to make?
I want to do it like in the WhatsApp application. For this I need to use a TabStrip.
Example:
577f5be5ff7eef884c18883bcb8cddeb6532a8e5c123d5f7fd680a8b5a63be1e_800.jpg
Well, in general, I would like to fix this bug in TabStrip. I would like to fix it so that other users do not face this problem...
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I want to do it like in the WhatsApp application. For this I need to use a TabStrip.
Example:
View attachment 120983
Well, in general, I would like to fix this bug in TabStrip. I would like to fix it so that other users do not face this problem...

i dont see here a "must" to use tabstrip. you can use simple views like labels, panels and just scroll the correct panel when clicking on the label.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
if you still want to use Tabstrip here is an example of changing the Checkbox to a simple Label with Fontawesome getting the same effect and here everything works fine.
 

Attachments

  • testliana.zip
    8.8 KB · Views: 228
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
if you still want to use Tabstrip here is an example of changing the Checkbox to a simple Label with Fontawesome getting the same effect and here everything works fine.
Yes, it's a good idea, but it won't fix the RadioButton problem. Is there an alternative to TabStrip that works fine with CheckBox and RadioButton?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Radiobutton works differently. Several radiobutton in 1 panel will only check a single choice and that also make sense.
Different from checkbox with a radiobutton u want to select a single option from several options.

u can do the same with radiobuttons. Fontawesome has a radiobutton icon. U just need to make sure to allow single selection in 1 panel.
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Radiobutton works differently. Several radiobutton in 1 panel will only check a single choice and that also make sense.
Different from checkbox with a radiobutton u want to select a single option from several options.

u can do the same with radiobuttons. Fontawesome has a radiobutton icon. U just need to make sure to allow single selection in 1 panel.
Yes I understand. Thanks.
Probably, this will have to be done, since there is no way to fix the TabStrip bug. I just wanted to make it possible for CheckBox and RadioButton to work normally with TabStrip so as not to rewrite most of the code, but if this is not possible I have no other choice.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
since there is no way to fix the TabStrip bug.
If all you are interested in is seeing all the checkboxes checked on the CLV in all pages of the Tabstrip as you scroll left and right, here is attached your project that you posted in post #1 with its CalSubDelayed and other stuff except for the bit of code I added to yours to show all checkboxes checked on all pages of the Tabstrip.
Beyond that, if you or anyone else have good reasons there is a bug with TabstripViewPager, it behooves you to really create a 'Bug' thread in the Wish/Bug forum to give Erel a chance to look at it and answer you. After all, he was the architect of the library.
 

Attachments

  • Red30ClvWithCheckboxes103121.zip
    19.4 KB · Views: 221
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
If all you are interested in is seeing all the checkboxes checked on the CLV in all pages of the Tabstrip as you scroll left and right, here is attached your project that you posted in post #1 with its CalSubDelayed and other stuff except for the bit of code I added to yours to show all checkboxes checked on all pages of the Tabstrip.
Beyond that, if you or anyone else have good reasons there is a bug with TabstripViewPager, it behooves you to really create a 'Bug' thread in the Wish/Bug forum to give Erel a chance to look at it and answer you. After all, he was the architect of the library.
Yes it works, thanks! What does the RefreshTabStrip subroutine do? Update TabStrip?
 
Upvote 0
Top