-1
Next, I have 2 questions that relate, so I’ll ask on 1 topic.
Well, I use this query to return a list of strings with product names.
public List<String> getMedico() {
List<String> list = new ArrayList<>();
Cursor cursor = database.rawQuery("SELECT nome FROM Armas Where Classe like 'médico' ORDER BY nome ASC", null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
list.add(cursor.getString(0));
cursor.moveToNext();
}
cursor.close();
return list;
}
When I click on a list item it opens a new detail page, which shows all the other attributes of the product. Then, on this page, I recover the image by passing as parameter the name of the clicked item.
public byte[] getImage(String name) {
byte[] data = null;
Cursor cursor = database.rawQuery("SELECT imagem FROM Armas WHERE nome = ?", new String[]{name});
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
data = cursor.getBlob(0);
break;
}
cursor.close();
return data;
}
Blz, it works smoothly. Now, what I need: Return an "image list". Instead of returning the name, I want to return the images and place them in a listview. But I have no idea how to do it. But blz, in doing so, takes the second question: When it is ready, it will return 300 images of 15kb each. Overall it gives almost 4mb. Return this much image can weigh in the application when opening this screen? And if you have 3 fragments returning 300 images each?
Ah, I want to do in sqlite and not put in drawables pq beyond the image will have name and description. Or it would be better to put in drawables, put in sqlite only the image path and return it somehow?
Well, I’m currently doing with sqlite, and since the images are already small, it doesn’t seem to have lost quality, but it didn’t answer what I asked
– Marceloawq
The first question: "Only I have no idea how to do it" Answer: "...you will have to use a library to load the images, like Glide, for example. It’s very simple to use..." The second question: "Can return this much image can weigh on the application when opening this screen?" Answer: "... In both cases, you will have to use a library..." Will weigh and crash the app. You’ll have to use a lib to manage image loading.
– Mr_Anderson
Starting, of course, from the principle that you already have a string arrayList with the image links or an int array, in which case it would be the drawable.
– Mr_Anderson
That’s why I told you to save the images as strings (links from an external server) or as ints (which is the drawable) so you don’t have difficulties at the time of the query. I think waste of time inserting images directly in db, pq have to convert and disconnect all the time...
– Mr_Anderson