B4J Question set image into imageview

tufanv

Expert
Licensed User
Longtime User
Hello,

I have a declaration of : dim x as image
and it has an image loaded.

is it possible to set an imageview's image to image of x ?

When I try it I get :

B4X:
(ClassCastException) java.lang.ClassCastException: javafx.scene.image.ImageView cannot be cast to javafx.scene.image.Image

thanks
 

stevel05

Expert
Licensed User
Longtime User
It would be helpful if you show the code you tried.

The message implies that you are trying to set the Image to the ImageView which should be:

B4X:
X = ImageView1.GetImage

If you want to set the imageView to hold the image then it should be:

B4X:
ImageView1.SetImage(X)
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
It would be helpful if you show the code you tried.

The message implies that you are trying to set the Image to the ImageView which should be:

B4X:
X = ImageView1.GetImage

If you want to set the imageView to hold the image then it should be:

B4X:
ImageView1.SetImage(X)
Hi , sorry i forgot to put my code , in fact i am trying to set an image to an imageview that is being hold in an object when tableview selected change .

When i do :

Imageview.setimage(row(0)) ( which row 0 is an imageview in tableview ) i get the error in the fist msg.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
So you will need to do something like:

B4X:
Dim iv as ImageView = row(0) 'Cast the object in row(0) to an imageview
ImageView.SetImage(iv.GetImage)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Be aware that it will be the same image object as in row(0). It should be OK if you overwrite the image in row(0) the link will be broken. But if you edit it in any way the image in the Imageview will also be changed.

It would probably be safer to store the source of the image in Imageview contained in row(0)'s tag, or a hidden column and load a new copy of the image into the main ImageView when it is selected.
 
Upvote 0
Top