Listview and button image

anaylor01

Well-Known Member
Licensed User
Longtime User
I have 16 buttons that are created with the code below. When any of the buttons are clicked it opens a listview. When the user makes a selection on the listview I want to make that image the image of the button the user clicked on to open the list view. Any help would be appreciated.

B4X:
Dim x, y As Int
Dim width, offsetX, offsetY As Int
    width = 37dip
    offsetX = ((layoutval.Width - bts*47)/2)/2'left (100%x - width * sw - 10dip * 2  ) / 2
    offsetY = 20'top(100%y - width * sw - 10dip * 2) / 2

    For x = 0 To sw
        For y = 0 To 1
            Dim b As Button
            b.Initialize("button") 'All buttons share the same event sub
            Activity.AddView(b,offsetX + x * (width + 3dip), offsetY + y * (width + 3dip), width, width)
            Buttons(x, y) = b 'store a reference to this view
        Next
    Next

B4X:
Sub Button_Click
    'Using Sender we find the button that raised this event
    Dim b As Button
    b = Sender
    'If b.Text <> "" Then Return 'Already used button

bt = Sender
Dim packages As List
Dim bt(500) As BitmapDrawable

listview1.Visible = True
 

anaylor01

Well-Known Member
Licensed User
Longtime User
I think I found my answer. You can't link back to the original button. Seems like there should be a way to tell what button it was and put it in a variable. Oh well. Guess I will have do this the LOOONNGGG way.
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
Another question. I have 16 buttons. I need to do something like "button" & btnnmbr.background = "picture".
My problem is getting the dynamic button number to work. My buttons are named button1, button2, button3 and so on.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
That will not work, as you cannot reference a view by its name in that way.

You need a list of the buttons and then you can step through the list.
 
Upvote 0
Top