Android Question Noob question regarding the designer

Mark.S

Member
Licensed User
I've never used the designer in B4A, I've always created my views in code.
Current project (for a use on a 8" Tab) uses over 120 views and growing!

Recently I found Earls TabStripViewPager and it would be great to split the program across 3 pages.
but because the Tabstrip only works with views created within the designer it looks like I'll have to re-work
the entire display layout of the project.

Almost all my views are within arrays, How do you create them within the designer?
placing one button in the designer and accessing it with;


B4X:
Private ControlLabel(10) as label 
Dim Text() As String = Array As String("PubCo","Site Name","M/c Type","M/c Name","Position","AWP Terms","Weekly Rent £","PubCo Share","Shortfall To","M/c Float £")
    For X = 0 To 9
        Cd.Initialize2 (Colors.ARGB (0,193,249,202),0,0, Colors.Black)
        ControlLabel(X).Background = Cd
        ControlLabel(X).TextColor = Colors.Black
        ControlLabel(X).Gravity = Gravity.right
        ControlLabel(X).TextSize= 16
        ControlLabel(X).Text= Text(X)
        ControlLabel(X).Typeface = Typeface.DEFAULT
        ControlLabel(X).SetLayout (5dip, 38dip +(X*LineSpace) , 110dip, 20dip)  'Left,Top,Width,Height
    Next

Sure doesn't work :(.

With such a large amount of objects is it good practice to 'just throw' the views into the designer and
sort them out in code afterwards, because trying to align so many within the designer will be a nightmare!
 

sorex

Expert
Licensed User
Longtime User
I prefer the code method aswell (2 extra lines (init & addview) solves your problem) so I'm not sure about it but I guess you'll need to fill the array first.

B4X:
Private ControlLabel(10) as label=array as label(label1,label2,label3,label4,label5,label6,label7,label8,label9,label10)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you have a lot of views already it will seem like hard work importing them into the designer, but if you had started with the designer, it would have been easy.

As you are assigning the same parameters to a block of labels, you would have set one first, then copied it. Or you can change shared parameters by selecting a number of views and changing one value.

If you use the designer properly, it makes designing a layout to run on different devices easier.

With such a large amount of objects is it good practice to 'just throw' the views into the designer and
sort them out in code afterwards
No.

because trying to align so many within the designer will be a nightmare!
That is why there are designer scripts.
 
Upvote 0

Mark.S

Member
Licensed User
Thanks for your reply's guys.
But I'm missing a trick or some brain cells:confused:

Adding 10 labels into the designer, label1 ......etc and declaring them in Globals
B4X:
Private ControlLabel(10) as label=array as label(label1,label2,label3,label4,label5,label6,label7,label8,label9,label10)
creates;
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

What's going on?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just put the array definition in the Globals sub

And the assignment in the Initialize sub after you have loaded the layout
 
Upvote 0

Mark.S

Member
Licensed User
I've tried all the permutations I can think off, still no luck.
can someone please give me the three lines of code so this brain freeze will stop!

B4X:
Sub Globals
    Private TabStrip1 As TabStrip
    Private ControlPanel As Panel
    Private ControlLabel(10) As Label
    Dim Cd As ColorDrawable
    Dim LineSpace As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    LineSpace = 28dip  'space between labels / Inputs
    Activity.LoadLayout("Main")
    TabStrip1.LoadLayout("Page1", "Control Page")
    TabStrip1.LoadLayout("Page2", "Blank")
    TabStrip1.LoadLayout("Page3", "Blank")

'Create and Display Control Panel
    Cd .Initialize2 (Colors.ARGB (255,193,249,202),35,2, Colors.Black)       
    ControlPanel.Background =Cd
    ControlPanel.SetLayout(10dip, 10dip, 418dip, 330dip) ' (Left,Top,Width,Height)
    ControlLabel(10) =Array As Label(label1,label2,label3,label4,label5,label6,label7,label8,label9,label10)
    Dim Text() As String = Array As String("PubCo","Site Name","M/c Type","M/c Name","Position","AWP Terms","Weekly Rent £","PubCo Share","Shortfall To","M/c Float £")
    For X = 0 To 9
        Cd.Initialize2 (Colors.ARGB (0,193,249,202),0,0, Colors.Black)
        ControlLabel(X).Background = Cd
        ControlLabel(X).TextColor = Colors.Black
        ControlLabel(X).Gravity = Gravity.right
        ControlLabel(X).TextSize= 16
        ControlLabel(X).Text= Text(X)
        ControlLabel(X).Typeface = Typeface.DEFAULT
        ControlLabel(X).SetLayout (5dip, 38dip +(X*LineSpace) , 110dip, 20dip)  'Left,Top,Width,Height
    Next
    
End Sub

error occurs on; Activity.LoadLayout("Main")
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Then the problem is likely to be somewhere in your layout file. Can you post it?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I've tried all the permutations I can think off, still no luck.
B4X:
ControlLabel(10) =Array As Label(label1,label2,label3,label4,label5,label6,label7,label8,label9,label10)
should be:
B4X:
ControlLabel =Array As Label(label1,label2,label3,label4,label5,label6,label7,label8,label9,label10)
Also , you have to redim each CD (colorDrawable) for each label unless all labels are the same size, then you get away with it. As Steve mentioned, the problem may also lie in your layout, if what I suggest does not help.
 
Upvote 0

Mark.S

Member
Licensed User
I've attached the code that's causing the problem, it's something really stupid that I can't see!
I know there's a problem with the syntax of 'Controllabel =Array as label (label1.......'
But the real problem is how to I address an array of views created in the designer.

Thanks in advance:)
Mark.
 

Attachments

  • TabStrip.zip
    12.6 KB · Views: 163
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You have a label in the designer called ControlLabel, and a Global variable called ControlLabel(10).

This is causing the error you are getting.

You need a separate Variable to hold the other labels, and as Klaus pointed out, you need to Define the Labels as well.
 

Attachments

  • TabStrip.zip
    13.1 KB · Views: 154
Upvote 0

Mark.S

Member
Licensed User
Sorry for the delay to thanking everyone that contributed, domestics sometimes takes precedence over coding (Not Offen!!)
This forum is brilliant, Period!
 
Upvote 0
Top