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

Anser

Well-Known Member
Licensed User
Longtime User
Hi all,

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

B4X:
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?

B4X:
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:

Anser

Well-Known Member
Licensed User
Longtime User
I am using the following code to display an image on ListView and is working fine.

B4X:
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?

B4X:
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
 
Upvote 0
Top