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

Discussion in 'Android Questions' started by Eugène Rappe, May 29, 2019.

  1. Eugène Rappe

    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
     
  2. DonManfred

    DonManfred Expert Licensed User

    Please use Code tags when posting code.
     
  3. MarkusR

    MarkusR Well-Known Member Licensed 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.
     
  4. Eugène Rappe

    Eugène Rappe Member Licensed User

    I don't understand English very well. I am new to using the forum. I don't understand "Please use Code tags when posting code"
     
  5. Eugène Rappe

    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."
     
  6. MarkusR

    MarkusR Well-Known Member Licensed User

    Snap_2019.05.29_16h23m03s_001.png
     
  7. DonManfred

    DonManfred Expert Licensed User

  8. MarkusR

    MarkusR Well-Known Member Licensed User

    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
    Code:
    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
     
  9. Star-Dust

    Star-Dust Expert Licensed User

    You are a diplomat, you have thought about your political career :D:D:D:D:p
     
  10. DonManfred

    DonManfred Expert Licensed User

    yes but failed miserably :D:D:D
     
  11. Star-Dust

    Star-Dust Expert Licensed User

    Strange, I would definitely vote for you ;)
     
  12. MarkusR

    MarkusR Well-Known Member Licensed User

    we have also "Foreign Languages" section here or maybe you can speak german better because you are from Belgium
     
  13. klaus

    klaus Expert Licensed User

    Il y a même un forum en français :).
    There does exist even a forum in french :).
     
    MarkusR likes this.
  14. Star-Dust

    Star-Dust Expert Licensed User

    Perhaps the Flemish speaks
     
  15. klaus

    klaus Expert Licensed User

    Perhaps also, but from his profile his occupation is: retraité
    And this is a frech word.
     
  16. Eugène Rappe

    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.
     
  17. Star-Dust

    Star-Dust Expert Licensed User

    Do something very useful by keeping yourself active with the programming. I congratulate you

    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
     
  18. klaus

    klaus Expert Licensed User

    Bienvenu dans la 'famille' B4X!
    Welcome in the B4X 'family'!
     
  19. MarkusR

    MarkusR Well-Known Member Licensed User

    you saw #8 ?
    i think it is easy to understand.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice