Android Question Can not get button text value

dannyjon

Member
Licensed User
Longtime User
Probably a really simple thing I have missed...

Buttons are in scrollview, on the buttonclick event I need to return the text of the button.
Whatever button is clicked the event ALWAYS returns 5 (the xth value of the loop). The designer has only the scrollview on it, no buttons.
Thanks!

Sub Globals
Dim ScrollView1 As ScrollView
Dim bt As Button
Dim pnl As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("sv1")
ScrollView1.Panel.Height = 2000
For i = 0 To 5
bt.Initialize("bt")'moving this about has no effect on the click
bt.Color=Colors.Yellow
bt.Text=i
ScrollView1.Panel.AddView(bt, 5dip, 5dip + i * 200dip, ScrollView1.Width - 10dip, 190dip)
Next
bt.Text=""
End Sub

Sub bt_click
Dim t As String = bt.Text
Msgbox(t,"click")
End Sub
 

mangojack

Expert
Licensed User
Longtime User
B4X:
Sub Globals
   Dim ScrollView1 As ScrollView   
   Dim pnl As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("sv1")
   ScrollView1.Panel.Height = 2000
   For i = 0 To 5
   Dim bt As Button   ' .....  @@ Dim button here
   bt.Initialize("bt")
   bt.Color=Colors.Yellow
   bt.Text=i
   ScrollView1.Panel.AddView(bt, 5dip, 5dip + i * 200dip, ScrollView1.Width - 10dip, 190dip)
   Next
End Sub

Sub bt_click
   Dim  b As Button
   b = Sender
   Log (b.Text)
End Sub
 
Upvote 0
Top