Autocomplete with image and text

3

I would like to do an AutoComplete on Android (java / android studio) with text and image, so I found a site that shows a very practical example of how to do it, I tested it and it worked perfectly unfortunately unfortunately I I do not want to load the images from resource drawable as it is in the example, I would like to put the images by bitmap which are the images that I capture by url, so I would like to insert by bitmap but unfortunately I searched in google and so far I could not find a solution, even here has 2 post of a person asking the same thing but apparently did not have the solution, if anyone can help me I will be very grateful. Thank you.

Obs URL: link

    
asked by anonymous 09.07.2016 / 16:00

1 answer

0

I think the best way to solve your problem is for the images in the assets folder, which is always better if this folder is created in "../app/main/assets", in my case, I use this function below to get the images from the assets folder, fill a list with them and process them as I want:

    private ArrayList<Bitmap> getImages(Context c) {
    String[] _List;
    String[] files = new String[0];
    ArrayList<Bitmap> result = new ArrayList<Bitmap>();
    // abre a pasta assets usando AssetManager
    AssetManager assetManager = c.getAssets();
    try {
        // "myfolderimages" é uma pasta na minha pasta assetes
        // aqui eu preciso inverter a ordem delas segundo o criterio "wH"
        // nessa linha eu preencho uma lista com os nomes dos arquivos na pasta
        _List = c.getAssets().list("myfolderimages");
        files = wH.equals("S") ? _List : display.reverseList(_List);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (files != null)
        for (int i = 0; i < files.length; i++) {
            InputStream open = null;
            try {
                // nesta linha eu preencho o array com as imagens contidas na lista de nomes
                open = assetManager.open("myfolderimages/" + files[i]);
                Bitmap bitmap = BitmapFactory.decodeStream(open);
                result.add(RotateBitmap(bitmap, 30.0f));
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (open != null) {
                    try {
                        open.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    // retorna o array com as imagens
    return result;
}

Dai I use it like this:

// ...
List<Bitmap> images = new ArrayList<Bitmap>();
// ...
LinearLayout meuLayout = new LinearLayout(this);
images = getImages(context);
// ...
ImageView minhaImagem = new Imageview(this);
minhaImagem.setImageBitmap(images.get(10);
meulayout.addview(minhaImagem);
setcontentview(meulayout);

This is just an example, adapt it according to your need

I hope it helps

    
09.07.2016 / 16:25