Android Question Assign to dynamically created button

Acklim

New Member
Licensed User
Longtime User
Hi,
I have a simple problem but I can't do it!
I have created 20 button in a panel in a scroll view along with tags numbering.
And I have a few specific buttons outside the scroll view.
When I press a specific button outside the scroll view I want to assign certain words to the 20 buttons created in the scroll view panel.
How do I write to the text on the dynamically created buttons in the scroll view
Pls help
Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Can you upload a sample project which shows the problem?

Are you talking about ONE panel containing x buttons?
You can do:
Create a global list (or array if you know the exact amount of buttons)
While adding the buttons you can add the buttons to the list.
Later you can use this list to get a reference to the buttons back to change text, color, whatever
 
Upvote 0

Ohanian

Active Member
Licensed User
Longtime User
Hi,
Hi,
I have a simple problem but I can't do it!
I have created 20 button in a panel in a scroll view along with tags numbering.
And I have a few specific buttons outside the scroll view.
When I press a specific button outside the scroll view I want to assign certain words to the 20 buttons created in the scroll view panel.
How do I write to the text on the dynamically created buttons in the scroll view
Pls help
Thanks

Hi,
here's a sample :
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim scHolder As ScrollView
    Dim btnOutside As Button
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

    scHolder.Initialize(0)
    btnOutside.Initialize("btnOutside")
    btnOutside.Text = "Do Magic!"

    Activity.AddView(scHolder, 0, 0, 100%x, 90%y)
    Activity.AddView(btnOutside, 0, 90%y, 100%x, 10%y)

    Dim i As Int
    For i = 1 To 20
        Dim btnInside As Button
        btnInside.Initialize("")
        btnInside.Tag = i
        btnInside.Text = "Inside Button #" & i
        btnInside.Gravity = Gravity.CENTER
        scHolder.Panel.AddView(btnInside, 10%x, scHolder.Panel.Height, 80%x, 50dip)
        scHolder.Panel.Height = scHolder.Panel.Height + 60dip
        scHolder.Panel.Invalidate
    Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnOutside_Click
    For Each vView As View In scHolder.Panel.GetAllViewsRecursive
        If vView Is Button Then
            Dim btnView As Button
            btnView = vView
            btnView.Text = "Hello #" & btnView.Tag
            btnView.Invalidate
        End If
    Next
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
File-Export to zip does not work?

Do you really expect me to do the work now to create a new project, insert your code there and so on?

It would be much easier for me to help if you have uploaded a project directly.

I already told the solution what you could do to archieve your goal.
 
Last edited:
Upvote 0

Ohanian

Active Member
Licensed User
Longtime User
File-Export to zip does not work?

Do you really expect me to do the work now to create a new project, insert your code there and so on?

It would be much easier for me to help if you have uploaded a project directly.

I already told the solution what you could do to archieve your goal.

Hi,
my code is an answer, not a question ;)
 
Upvote 0
Top