1. Draccus's Avatar
    I've made a custom checkbox with two images. One for an empty box and a second one with a checkmark in the box. It works fine but I'm trying to figure out how to do this with 7 buttons. In C# I would probably make some sort of array of buttons so that they can do something like (pseudo C# code)

    Button Buttons = new Button[7];
    foreach ( Button b in Buttons )
    b.Image = "cbempty.png";

    void Button1_Click ()

    void Button2_Click ()

    void ToggleButton ( int index )
    Buttons[index].Image = (Buttons[index].Image=="cbempty.png")?"cbchecked.png":"cbempty.png";

    The above is something like I want to accomplish. I would rather not make a seperat if statement for every single button.
    02-08-2011 12:22 AM
  2. rshives's Avatar
    One way you could solve the problem is to create the buttons you need. Then place them all inside a List.

    VARIABLE -> MAKE A LIST -> Button1
    -> Button2
    -> Button3

    Then you could iterate through the list or use list indexes (which start at 1 btw) as in your psudo code.
    02-08-2011 01:10 PM
  3. Draccus's Avatar
    Okay so far I figured this much out.

    Buttons -> Make a list -> (component) Button 1
    (all buttons, 7 in all)

    The next problem is hit when trying to assign a value to the Image field.

    foreach variable (name) temp
    var b = temp
    var b.Image = "checked.png";
    in list (global) Buttons

    The problem is that b is just a variable. It has two blocks and no properties from the Button. Though it seems that the array list is full of buttons, the access right now seems like a normal variable (either set or get values, not specific fields).
    02-08-2011 09:30 PM
  4. rshives's Avatar
    That is a limitation with App Inventor. You cannot dynamically set the UI element (or any element for that matter) properties.

    Even though you have a List of Buttons, the List doesn't know it holds Button types.

    I'm not sure you can solve this problem using App Inventor yet.
    02-10-2011 10:38 AM