I want to display an image in an ImageView. I have several records in the database with a title, a description, the latitude, the longitude and an image of the place. I watch the title and the description, but not the image. The rest is not necessary to display it.
The image is not in the database, is caught in the gallery and its uri is stored as a String.
Data are displayed using a ListView.
Here is the code:
For every item of the ListView:
For the ListView:
To save items in the ListView first I retrieve data from a cursor and I insert them in an ArrayList of type of a class named Lugar.
When I run the project I don't watch any error in the logcat. The only problem I have is that the photo is not displayed.
How can I display the image?
I changed lgu for lugitem but I can't watch the photo.
I checked the value of rutaimg and it's different in every record of the database. Well, this is not exact. I have three records in the database: two without image and one with image. When I wanted to check the value of rutaimg that is the path of the image, the records of the database that hasn't image had the value: com.app/mapa/2130837504 and the other without image has not value and I don't know why.
When I wanted to check the value of rutaimg that is the path of the image, the records of the database that hasn't image had the value: com.app/mapa/2130837504 and the other without image has not value and I don't know why
What does that mean? The way I read it is:
For one entry in the database that does not have an image, the value assigned to rutaimg was com.app/mapa/2130837504.
For the second entry in the database that does not have an image, there was no value assigned to rutaimg. (null?)
This sounds like the values you are getting from the database are incorrect - one of them has a value, the other one doesn't, and you expect neither of them to have a value. If the value in rutaimg is not correct then how can you say you know the value in the database is correct? Have you used some other tool to inspect it directly?
Or maybe I mis-read what you wrote.
When I insert one record in the database and I want to list the whole, I can watch all data except the image. Which value has rutaimg? Blank. So I know that the path for the image is not correct.
I think where is the error but I don't know how to fix it. It's in the value of the image's path when I insert a record in the database.
When I insert the image in an ImageView I want to obtain the path of this image and I do it as following:
Here is the xml file:
The ImageView where I insert the image is the second one, that has imgFoto id.
I insert the image selecting it from the gallery and what I want to do is to save the image's path in a String and when I list all records of the database I become the String path into Uri.
When I retrieve all the records in the database I can watch that all image values are the same.
How can I save the path of a selected image correctly?
So what image are you actually trying to load/store? Where does it exist? How do you load it initially?
The user click on the save button and the title, the description and the image are saved in the database. But the image is not stored in the database, it's its path in a String format. But I don't know if it's possible to do something like this. I think so. The problem is that every time the user select an image it's a different one and I don't know how to store the path in the database.
Alex Munozz wrote:The image I want to store is one selected by the user from the gallery. The user click on the ImageView and then he can choose insert an image from the gallery or from the camera. He must select from the gallery because it's the only option I have coded now. When the user has selected the image it is showed in an ImageView.
Okay, so at some point the user selects an image and you get the URI back as a result, and you use that URI to load the image into the ImageView, correct? Then what you need to do is store the URI that you get as a response to the user action and put that in the database. You will not be able to re-create that URI so you need to store it in a variable and when needed, put it in the database.
To answer the question: you put it in a variable someplace - or if you are really safe, you have a database table that you immediately store the URI to as soon as the user selects it. Then when the user Saves you simply copy from one location in the DB to another.