Android Question How to create label in sequence with spinner's text...

MroBurk

Member
Licensed User
Hi there, I need to create a label in sequence with Spinner's text like in the images attached. I tried the link below but it doesn't better for my app...
Thanks for any ideas..

 

Attachments

  • spinner4.jpg
    spinner4.jpg
    59.1 KB · Views: 164
  • spinner3.jpg
    spinner3.jpg
    56.5 KB · Views: 178
  • spinner2.jpg
    spinner2.jpg
    54.6 KB · Views: 174
  • spinner1.jpg
    spinner1.jpg
    50.8 KB · Views: 182

Mahares

Expert
Licensed User
Longtime User
I need to create a label in sequence with Spinner's text like in the images attached. I tried the link below but it doesn't better for my app...
If you are looking to color the label based on the color chosen in the spinner, you can create a sub like this:
B4X:
Sub ColorLabel(l As Label)
    If a.Contains("red") Then
        l.color = Colors.Red
    else if a.Contains("green") Then
        l.color = Colors.Green
    else if a.Contains("yellow") Then
        l.color = Colors.Yellow
    End If
End Sub
And your button1 code will be something like this:
B4X:
Private Sub Button1_Click
    If Label1.Text = "" Then
        Label1.Visible=True
        Label1.Text= a
        ColorLabel(Label1)
    Else        
        If Label2.Text = "" Then
            Label2.Visible=True
            Label2.Text= a
            ColorLabel(Label2)
        Else                
            If Label3.Text = "" Then
                Label3.Visible=True
                Label3.Text= a
                ColorLabel(Label3)
            Else
                If Label4.Text = "" Then
                    Label4.Visible=True
                    Label4.Text= a
                    ColorLabel(Label4)
                Else
                    If Label5.Text = "" Then
                        Label5.Visible=True
                        Label5.Text= a
                        ColorLabel(Label5)
                    Else
                    If Label6.Text = "" Then
                        Label6.Visible=True
                        Label6.Text= a
                        ColorLabel(Label6)
'finish rest of labels like above
End sub

1641565540171.png
 
Upvote 0

MroBurk

Member
Licensed User
Thanks for this, but my question is: I need to create label without labels created in the design... But from the code... if I select an item and I click on the button, the code creates a label with text selected... I don't know if this is possible... I see xui.CreateLabels but I don't know how to use it...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
but my question is: I need to create label without labels created in the design... But from the code
If your question was to create the labels by code, why did you then upload your project with the labels already created with the designer.
I don't know if this is possible..
It is possible. Here is the code you need for an array of 8 labels by code. Make sure the layout Layoutlabel when loaded should only have the 3 radio buttons, spinner1 and button1. The labels will be created by code in one column, but you can tweak the app to make 3 columns of labels. Please note that after the 8th label the button1 is disabled so the app stops adding labels.
B4X:
Sub Globals
    Private a As String
    Private Panel1 As Panel
    Private RadioButtonGreen As RadioButton
    Private RadioButtonRed As RadioButton
    Private RadioButtonyellow As RadioButton
    Private Spinner1 As Spinner
    Dim GreenArr(2), RedArr(3),YellowArr (4)As String
    Private Button1 As Button

    Private n As Int =8   'number of labels. You can change this to any number to have more labels
    Private lbl(n) As Label
    Private i As Int =0
End Sub
B4X:
Private Sub Button1_Click
    Dim w =200dip, h=50dip As Float
    lbl(i).Initialize("lbl")
    Activity.AddView(lbl(i), 0,i*60dip+200dip, w, h)
    lbl(i).Text= a
    lbl(i).TextSize = 20
    ColorLabel(lbl(i))
    i=i+1
    If i=n Then Button1.Enabled =False
End Sub
 
Upvote 0

MroBurk

Member
Licensed User
Great!! That is what I needed!!! Thank you very much!!!!!

Ps.: I posted that code for an example of what I wanted to create...
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Upvote 0
Top