Changing checkbox height

zetadan

Member
Licensed User
Longtime User
Sorry for the noob question but I just can't figure out how to change the size of the checkbox that I am using inside a scrollview. I have been able to change the text size by using something like: chk.textsize = 30

However, when I use: chk.Width = 10 I get a runtime error that says java.lang null exception

I know I am doing something stupid but just don't know what. :BangHead:

Any help would be greatly appreciated.

Dan
 

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't understand what exactly you want to do.
You don't give enought information.
But, having a TextSize = 30
and a Width of 10 looks very strange to me.
First you should use dip values and not 'absolute' pixel values (10dip).

What about the CheckBox.Height ?
What is the ScrollView.Width ?

Best regards.
 
Upvote 0

zetadan

Member
Licensed User
Longtime User
Thanks Klaus, I will try to elaborate. The following is mainly copied from an example given by Erel with just a few mods for me to test how this works. I plan to include in another project once I understand. I hope I have addressed your questions below.

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
    Dim ScrollView1 As ScrollView
    Dim lstChecks As List
    Dim height As Int
    height = 100dip
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ScrollView1.Initialize(0)
    Dim pnl As Panel
    pnl = ScrollView1.Panel
    Activity.AddView(ScrollView1, 0, 0, 100%x, 100%y)
    lstChecks.Initialize
    
    For i = 1 To 100
        Dim chk As CheckBox
        chk.Initialize("")
        chk.Text = "Item #" & i
      chk.TextSize = 30
      chk.Width = 10
        lstChecks.Add(chk)
        Dim lbl1 As Label
        lbl1.Initialize("")
        lbl1.Text = "Value #" & i
        lbl1.Gravity = Gravity.CENTER_VERTICAL
        pnl.AddView(chk, 0, height * (i - 1), 120dip, height)
        pnl.AddView(lbl1, 125dip, height * (i - 1), 120dip, height)
    Next
    pnl.height = lstChecks.Size * height
 End Sub

I understand about using dips, but could that be the real problem here? I am pretty sure I have tried the exact same code with dip values. I have also tried to modify the checkbox height with the same results.

Please bear with my noobness.

Dan
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should remove chk.Width = 10 because you cannot acces the width property before having added the view to it's parent view.
The width of chk will be 120dip defined in pnl.AddView(chk, 0, height * (i - 1), 120dip, height).

Best regards.
 
Upvote 0
Top