Android Question Convert Object to String

Mark Baars

Member
Licensed User
Longtime User
Hello,

I have 12 imageviews holding bitmaps, representing a set of cards. I use the same click event for all imageviews. To determine wich card was clicked, I try to read out the name of the attached bitmap. I think I need a function like "ToString" but can't seem to find how to do this in B4A.

In the code below the line "clickedBitmap = b.bitmap" generates an error. Intellisense tells me: "Object converted to string. This is probably a programming mistake. (warning #7)". The line above that, writing the contents of b.bitmap to the log works just fine.

B4X:
Sub Card_Click
    ' Using Sender we find the button that raised this event
    Dim b As ImageView
    Dim clickedBitmap As String
    b = Sender

    imgHuge.Bitmap = b.bitmap
    Log ("b.bitmap = '" & b.bitmap & "'")

    ' When SET-card is clicked: b.bitmap = 'android.graphics.Bitmap@c5b66a9'

    clickedBitmap = b.bitmap

    Log ("clickedBitmap = '" & clickedBitmap & "'")

    If clickedBitmap = "android.graphics.Bitmap@c5b66a9" Then
        Msgbox ("SETTINGS", "")
        ' TODO: Open settings-activity
    Else
        For x = 0 To 2
            For y = 0 To 4
                Cards(x,y).SetVisibleAnimated(1000,False)
            Next
        Next

        imgHuge.SetVisibleAnimated(1000,True)
    End If
End Sub

I think I need to find a way to convert the content of b.bitmap to a string, so I can determine it's value. Any help on this is greatly appreciated.

Thanks,

Mark
 

stevel05

Expert
Licensed User
Longtime User
You can add a Tag to the ImageView to determine which was clicked.
B4X:
If b.Tag = "Settings" Then
    MsgBox("SETTINGS","")
Else
    .......

The references you are trying to use 'android.graphics.Bitmap@c5b66a9' are internal references and will change each time you run the app.

You can add information to the ImageView's Tag field either in the designer or in Code.
 
Upvote 0
Top