Android Question Error: inconvertible types

Discussion in 'Android Questions' started by trueboss323, Feb 20, 2015.

  1. trueboss323

    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:
    Code:
    Dim List1 as CustomListView

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

    Sub CreateListItem(Text As String, Text2 As String, Width As Int, Height As Int, Image As BitmapAs 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, 
    2dip2dip50dip, Height - 4dip'view #0

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

    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
     
    DonManfred likes this.
  3. trueboss323

    trueboss323 Active Member Licensed User

    Your method actually worked! Thank you very much.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice