Listview of images and quantity - Android [closed]

-1

Next, I have 2 questions that relate, so I'll do it in 1 topic.

Well, I use this query to return a list of strings with the names of the products.

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 details page, which shows all the other attributes of the product. Here, on this page, I retrieve the image by passing the item name as a parameter.

 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, this works quietly. Now, what I need: Return a "list of images". Instead of returning the name, I want to return the images and put them in a listview. But I have no idea how. But blz does this by asking the second question: When it is ready, it will return 300 images of ± 15kb each. Overall it gives almost 4mb. Returning this much of image can weigh in the application at the time of opening this screen? What if you have 3 fragments returning 300 images each?

Ah, I want to do in sqlite and not put in drawables because the pq beyond image will have name and description. Or would it be better to put in drawables, put in sqlite only the path of the image and return it in some way?

    
asked by anonymous 26.01.2017 / 15:17

3 answers

2

Dude you could first do a DTO Object with the attributes Name and Image, saved in SQLite. In this, to limit, try to use a SQL where you limit the results by pages, type:

SELECT nome, imagem FROM Armas Where Classe like 'médico' ORDER BY nome LIMIT 5, 10

This will return 5 from row 10. When you need more images, just change the value from 10 to 15, 20 .. Read more about this here .

Since you will use a large number of results, use a RecyclerView. Using the Scroll Listener, you can retrieve more results when the user scrolls the list. Read about it here .

And so, when the user clicks on an item in the list, just get the name saved in the DTO Object and open the fragment.

I hope this helps you, hugs!

    
26.01.2017 / 20:23
0

About images in databases:

I do not recommend saving images inside the database, for query performance reasons, and we are not very limited when working with more resolutions - and as we know, devices have limited capabilities.

When we save the image in the bank, and we need to recover, we have to worry about doing the translation of text to image, and if we want to include, the same need arises. I always recommend using the app's cache folder (' /data/data/br.com.seuapp/images ') - external storage - so you can upload the images dynamically, using your app to search the server.

There is an Android Developer (Google) page that addresses how to display images efficiently , on this page you can read a bit about rendering, handling and displaying bitmaps.

Remembering: If we hit a photo in a resolution of: 5 megapixels (2592x1936 pixels), and we want to load / display it, we will use the whole 19mb, bursting the preload limit of many devices.

    
26.01.2017 / 17:18
0

Do not waste time trying to put images in SQLITE. You can do it, but you lose 99% of the resolution, making the image useless. Or you save in the drawable and insert the path in db, type R.drawable.img01 (which is nothing more than an int), or upload the images to some online server and save the link in db. In either case, you'll need to use a library to load images, such as Glide , for example. It is very simple to use. If you are on the adapter, for imgView.setResource.... , Glide.with(contexto).load(R.drawable.img1).into(imgView); or Glide.with(contexto).load("www.meuserv.com/img01").into(imgView);

    
26.01.2017 / 15:37