Android Question Write in Label.Text

Sinan Tuzcu

Active Member
Licensed User
Hi,

i have here a code for Listview in a ScrollView with TextBox include.
How can i write the TextBox in a for...Next loop with Number from 1 to 20

Can someone help me?

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: 1
    #VersionCode: 2
    #VersionName: 1.01
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

Sub Process_Globals

End Sub

Sub Globals
    Dim sv As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(70dip * 10)
    Activity.AddView(sv, 0, 0, 100%x, 100%y)
    For i = 0 To 9
        Dim p As Panel
        p.Initialize("")
        p.Tag = i
        p.LoadLayout("2")
        For v = 0 To p.NumberOfViews - 1
            p.GetView(v).Tag = p 'set the panel as the Tag value
        Next
        sv.Panel.AddView(p, 0, i * 70dip, sv.Panel.Width, 60dip)
    Next
End Sub

Sub button1_click 'handles all buttons
    Dim b As Button
    b = Sender
    Dim p As Panel
    p = b.Tag
    Dim txt As EditText
    txt = GetEditTextOfPanel(p)
    Msgbox("text entered: " & txt.Text, "Panel " & p.Tag)
End Sub

Sub GetEditTextOfPanel(p As Panel) As EditText
    For i = 0 To p.NumberOfViews - 1
        If p.GetView(i) Is EditText Then Return p.GetView(i)
    Next
End Sub
 

mangojack

Well-Known Member
Licensed User
Unsure of exactly what your trying to do. (why are you setting the panel to the Tag property of all views ?.

You should use Log instead of Msgbox.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    sv.Initialize(70dip * 10dip)
    Activity.AddView(sv, 0, 0, 100%x, 100%y)
    For i = 0 To 10
        Dim p As Panel
        p.Initialize("")
        p.LoadLayout("2")
        button1.Tag = i        '@@ only setting button tag with row index ...
        sv.Panel.AddView(p, 0, i * 70dip, sv.Panel.Width, 60dip)
    Next
 
    InsertText 'populate edittext
 
End Sub

Sub InsertText
    For i = 0 To sv.Panel.NumberOfViews -1
        Dim p As Panel = sv.Panel.GetView(i)
        Dim txt As EditText = p.GetView(1) '2nd view added in designer layout
        txt.Text = "I am EditText # "
    Next
End Sub

Sub button1_click 'handles all buttons
    Dim b As Button = Sender
    Dim p As Panel = b.Parent
    Dim txt As EditText = p.GetView(1)   '2nd view added in designer layout
 
      txt.Text  = txt.Text & b.tag
 
    Log($"text entered:  ${txt.Text} ,   Panel: ${b.tag}"$)
    'Msgbox("text entered: " & txt.Text, "Panel " & b.tag)
End Sub
 

Sinan Tuzcu

Active Member
Licensed User
Hi,

thanks for your help, bur I have one Label1 and one ToggleButton.
upload_2019-2-11_18-25-8.png

I have change your code for write Label1, but the code write only ToggleButton.

Why?

here the changed code:
B4X:
Sub Relais_In_ScrollView(Relais_Anzahl As Int)
    Dim counter As Int = 1
    Dim Chanel As Int = 1
   
   
    Relais_Anzahl = Relais_Anzahl -1
    ScrollView1.Initialize(385dip* 10) 'Innere Höhe definieren (nicht sichtbar) 32=193dip, 64=385dip
    ScrollView1.RemoveView
    Activity.AddView(ScrollView1, 2%x, 30%y, 96%x, 68%y) 'Sichtbare Linkaabstand, Obenabstand, Breite, Höhe definieren
    For i = 0 To Relais_Anzahl
        Dim p As Panel
        p.Initialize("")
        If counter > 128 Then
             counter = 1
             Chanel = Chanel + 1
        End If
        p.Tag = Chanel & "|" & counter
        counter = counter * 2
        p.LoadLayout("RelaisSwitchButton")
        Label1.tag = i
'        For v = 0 To p.NumberOfViews - 1
'            p.GetView(v).Tag = p 'set the panel as the Tag value
'        Next
        ScrollView1.Panel.AddView(p, 0, i * 60dip, ScrollView1.Panel.Width, 58dip)
    Next
    InsertText
    
End Sub
Sub InsertText
    For i = 0 To ScrollView1.Panel.NumberOfViews -1
        Dim p As Panel = ScrollView1.Panel.GetView(i)
        Dim txt As Label = p.GetView(1) '2nd view added in designer layout
        txt.Text = "Wohnzimmer "
    Next
 
Top