Android Question Problem with array button click new 2

Discussion in 'Android Questions' started by juniorteacher, Jul 1, 2015.

  1. juniorteacher

    juniorteacher Member Licensed User

    i use array to make button,
    how i identify that button i click?

    Code:
    dim button(13as button

    for i =  0 to 13 -1
    but(i).Initialize(
    "But")
    Activity.AddView(but(i),10%x + (i*11.5%x),14.5%y,11.5%x,8.3%y)
    next

    sub but(0)_click 'error in here
    msgbox("test","test")
    end sub
    please give me an example
     
  2. juniorteacher

    juniorteacher Member Licensed User

    if use but.tag

    i can't use function like but(0).enable =true
     
  3. sorex

    sorex Expert Licensed User

    put the array number (i in your case) as tag and then you should be able to do

    Code:
    sub but_click
    dim b as button
    b=
    sender
    log(b.tag)
    buttons(b.tag).enable=
    false
    end sub
    you better change the arrayname to buttons to avoid confusion
     
  4. klaus

    klaus Expert Licensed User

    Or simply:
    Code:
    Sub But_Click
        
    Dim b as Button
        b = 
    Sender
        b.Enable = 
    false
    End Sub
     
    RauchG and JordiCP like this.
  5. sorex

    sorex Expert Licensed User

    indeed Klaus, since it's the same button anyway that's even shorter.
     
  6. juniorteacher

    juniorteacher Member Licensed User

    buttons ???
    i'm already change it, but pull down menu did show the option for enable

    i have 13 button and give tag name every button
    can it disable button from button tag name like
    Code:
    Sub But_Click
        
    Dim b(13as Button = sender
        
    Dim btnid as int = btn().tag ' error in here
    b(12).Enable = false ' error in here
    End Sub
     
  7. sorex

    sorex Expert Licensed User

    it seems you don't really understand what you are writing there.

    look again at my example and the one from Klaus. It's all there.
     
  8. juniorteacher

    juniorteacher Member Licensed User

    my question is simple,
    how to make array button with single click and disable the button from name tag
     
  9. sorex

    sorex Expert Licensed User

    you will need to loop through the array and check the tags. if the right one passes you disable it.
     
    DonManfred likes this.
  10. juniorteacher

    juniorteacher Member Licensed User

    Code:
    dim buttons(13as button
    for i = 0 to 13 -1
    buttons(i).Initialize(
    "buttons")
    buttons(i).tag = i
    next

    sub buttons_click
    dim b as button = sender
    bid = b.tag
    b(btag).enable = 
    false
    end sub
    i want buttons(0) can disable buttons(3) or buttons(5)
     
  11. sorex

    sorex Expert Licensed User

    Code:
    sub buttons_click
    dim b as button = sender
    bid = b.tag
    b.enable = 
    false
    if bid=0 then
     buttons(
    3).enable=false
     buttons(
    5).enable=false
    end if
    end sub
     
    JordiCP likes this.
  12. JordiCP

    JordiCP Well-Known Member Licensed User

    I suppose the problem is that you are not declaring the buttons as Global variables. You must do so to be able to use them in the "buttons_click" event

    Code:
    Sub Globals
      
    Dim buttons(13as button
    end sub
    Sub Activity_Create(FirstTime as Boolean)
      
    for i = 0 to 13 -1
        buttons(i).Initialize(
    "buttons")
        buttons(i).tag = i
      
    next
    end sub

    Sub buttons_click
      
    dim b as button = sender
      bid = b.tag
      
    if bid=0 then
        buttons(
    3).enable=false
        buttons(
    5).enable=false
      endif
    end sub
     
    Gandalf and juniorteacher like this.
  13. juniorteacher

    juniorteacher Member Licensed User

    yes solved thanks very much.... that was true
     
Loading...