Android Question Update (color) a set of 64 buttons in a Panel using a For... Next loop from a Map list?

Eugène Rappe

Member
Licensed User
I built with the Designer two Panel of 64 buttons each.

In the first panel, with code, each time you click on a button, it changes color and thus switches between green and black.

I retrieved the status values of each button from the first Panel in a Map (here "Mpbtn1").

Once the diagram is built in the first Panel I would like to update the buttons of the second Panel in a single time from the Map data using a loop (for fun), in the genre For i=0 to 63 ...next.

Initialization of Map
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Leds64Dessin")
Mpbtn1.Initialize
Mpbtn2.Initialize
For i=1 To 64
istring=i
Mpbtn1.Put(istring,1)
Mpbtn2.Put(istring,1)

Next
End sub

Update Panel1
Sub Button_Click
Dim cd1,cd2 As ColorDrawable
Dim Btn As Button
Btn = Sender
cd1.Initialize(Colors.ARGB(255,47,255,19), 89dip)
cd2.Initialize(Colors.Black,89dip)
istring=Btn.Tag
cpt=Mpbtn1.Get(istring)
If cpt=1 Then
Btn.Background=cd2
End If
If cpt=2 Then
Btn.Background=cd1
cpt=cpt-2
End If
cpt=cpt+1
Mpbtn1.Put(istring,cpt)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Please use Code tags when posting code.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
you can't memory all your buttons in the list?
and copy the data from list 1 with all buttons to list 2 with all buttons.
 
Upvote 0

Eugène Rappe

Member
Licensed User
I don't know how to do "you can't memory all your buttons in the list?
and copy the data from list 1 with all buttons to list 2 with all buttons."
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
I don't know how to do "you can't memory all your buttons in the list?
and copy the data from list 1 with all buttons to list 2 with all buttons."
example , designer 4 buttons with event name "Button"
tag is used for memory a list index
button1 tag=0
button2 tag=1
button3 tag=0
button4 tag=1

B4J
B4X:
Sub Process_Globals
    Private MainForm As Form
       
    Private fx As JFX
    Private MainForm As Form
   
    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
    Private Button4 As Button
   
    Dim List1 As List
    Dim List2 As List
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   
    MainForm = Form1
    MainForm.Show
   
    MainForm.RootPane.LoadLayout("Layout1")
   
    List1.Initialize
    List2.Initialize

    List1.Add(Button1)
    List1.Add(Button2)

    List2.Add(Button3)
    List2.Add(Button4)
       
               
End Sub

'Event Name "Button" for all buttons
Sub Button_Click
   
    Dim Button1 As Button
    Button1 = Sender
   
    Button1.TextColor = fx.Colors.Red
    Dim index As Int = Button1.Tag 'Value from Designer
   
    Dim ButtonX As Button = List1.Get(index) 'Button Object by Index
    Log(ButtonX.Text)
   
    'copy property
    For Each B As Button In List2
        B.TextColor = Button1.TextColor
    Next
       
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Perhaps the Flemish speaks
 
Upvote 0

Eugène Rappe

Member
Licensed User
Thank you all for your help. I am an amateur and I cannot train under the same conditions as everyone else because of my disability (paraplegia) and my health problems. With nephews and nieces we have fun programming self-taught for educational projects if we are not too clumsy. I am Francophone (Wallonia). Due to my isolation I could not practice my English and I forgot a lot ( I know that this is not your problem DonManfred : but thanks for the quiz).My german is even worse than my English. I use also «reverso» to translate.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank you all for your help. I am an amateur and I cannot train under the same conditions as everyone else because of my disability (paraplegia) and my health problems. With nephews and nieces we have fun programming self-taught for educational projects if we are not too clumsy. I am Francophone (Wallonia). Due to my isolation I could not practice my English and I forgot a lot ( I know that this is not your problem DonManfred : but thanks for the quiz).My german is even worse than my English. I use also «reverso» to translate.
Do something very useful by keeping yourself active with the programming. I congratulate you

Perhaps also, but from his profile his occupation is: retraité
And this is a frech word.
You are polyglot and you have recognized a French word, I would have said it was Flemish ....
Then not always the profession indicated in the profile is a language of the spoken language ... see my occupation in the profile is written in English but I do not speak English
 
Upvote 0
Top