Android Question Sample Required : Display Image from MySQL using RDC on ListView/CustomListView

Discussion in 'Android Questions' started by Anser, Feb 10, 2015.

  1. Anser

    Anser Well-Known Member Licensed User

    Hi all,

    I have a table on a remote MySQL Database which contains the following columns

    Code:
    Item_code  Character(10)
    Item_Description  Varchar(
    300'Will contain long descriptive text
    Price  Decimal (10,2'Price of the product
    Image  MediumBlob ' Image of the product
    The maximum possible number of rows in the table will be 50

    I am confused regarding the view to be used for this purpose ie ListView, ScrollView OR CustomListView. Which one do you recommend ? After reading several posts, I understand that the ListView can be used if the number of Items are huge, but ListView has limited flexibility when compared to ScrollView and CustomListView. I also read that the CustomListView should be used only for displaying fewer records.

    I couldn't locate a sample showing how to retrieve the image from MySQL database and displaying it on the above said ListView/ScrollView/CustomListView. I found samples showing opening an Image file from Assets folder and displaying the same image on various rows of the list.

    If I have 50 rows from the Table. Do I have to DIM and initialize 50 Bitmaps for this inside the loop processing the records?

    Code:
    For Each records() As Object In result.Rows
      lv.AddTwoLines( records(result.Columns.Get(
    "Item_Code")) , _
                      records(result.Columns.Get(
    "Item_Description")) &CRLF& _
                      
    "Price : " & records(result.Columns.Get("Price"))  )  ' How do I add the image here
    Next
    I know that in the ListView AddTwoLinesAndBitmap is to be used instead of lv.AddTwoLines, but I not clear regarding retrieving image from a blob field and then displaying it.

    Please note that the column Item_Description contains a very long text approximately 300 characters.

    I don't know whether I should use CustomListView or ScrollView because the Item_description is 300 characters. I also don't know how substitute the above lines to use a CustomListView or ScrollView.

    Any help or sample code will be appreciated.

    Regards
    Anser
     
    Last edited: Feb 10, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    lion sobral likes this.
  3. Anser

    Anser Well-Known Member Licensed User

    I am using the following code to display an image on ListView and is working fine.

    Code:
    Dim Bitmap1 as Bitmap
    Bitmap1.Initialize(
    File.DirAssets, "Search.png")
    lvMenu.AddTwoLinesAndBitmap(
    "Search""Search Items",Bitmap1)
    How do I substitute the same to show image from database on a Listview from the Sub JobDone?

    Code:
    For Each records() As Object In result.Rows
       
    Dim oBitMap As Bitmap
       
    Dim buffer() As Byte
       buffer = records(result.Columns.Get(
    "Item_Picture")) ' Image Column
      'I am stuck after this point
      'How do I convert the image from variable buffer and then display it on ListView
      'I can't understand what kind of object is this BookImage (as given in the eg refered by you)
       'BookImage.Bitmap = reqManager.BytesToImage(buffer)
       lvMenu.AddTwoLinesAndBitmap(""FirstLine","SecondLine",buffer)
    Next
    Regards
    Anser
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    reqManager.BytesToImage converts an array of bytes to a Bitmap object:
    Code:
    oBitmap = reqManager.BytesToImage(buffer)
    'now add oBitmap to lvMenu
     
  5. Anser

    Anser Well-Known Member Licensed User

    Thanks Erel.

    It worked perfectly.

    Regards
    Anser
     
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