Android Question Error: inconvertible types

trueboss323

Active Member
Licensed User
I keep getting this error when I want to load my image inside a listview.

src\b4a\example\main.java:722: error: inconvertible types
_img1.setObject((android.widget.ImageView)(_image.getObject()));
^
required: ImageView
found: Bitmap
1 error

i'm not sure how exactly I could convert a bitmap into an ImageView, if that would solve the problem.
But here is the code I have:
B4X:
Dim List1 as CustomListView

List1.Add(CreateListItem("This is a text","This is another text", List1.AsView.Width, 50dip, LoadBitmap(File.DirAssets, "image.png")), 50dip, "")

Sub CreateListItem(Text As String, Text2 As String, Width As Int, Height As Int, Image As Bitmap) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim img1 As ImageView
    img1.Initialize("img1")
    img1.Gravity = Gravity.FILL
img1 = Image
    Dim title As Label
    title.Initialize("")
    title.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    title.Text = Text
    title.TextSize = 16
    title.TextColor = Colors.White
Dim subtitle As Label
    subtitle.Initialize("")
    subtitle.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.BOTTOM)
subtitle.Text = Text2
    subtitle.TextSize = 14
    subtitle.TextColor = Colors.White
    p.AddView(img1, 2dip, 2dip, 50dip, Height - 4dip) 'view #0

    p.AddView(title, 65dip, -6dip, 300dip, Height - 4dip) 'view #1
    p.AddView(subtitle, 66dip, -2dip, 300dip, Height - 4dip)
   
    Return p
End Sub
Any help would be appreciated!
 

sorex

Expert
Licensed User
just pass the image filename and load it in that sub which makes it easier to read the sub line.



it is probably bouncing on this

img1 = Image


img1 is an imageview and not a bitmap, try img1.bitmap=image instead
 

trueboss323

Active Member
Licensed User
just pass the image filename and load it in that sub which makes it easier to read the sub line.



it is probably bouncing on this

img1 = Image


img1 is an imageview and not a bitmap, try img1.bitmap=image instead
Your method actually worked! Thank you very much.
 
Top