android – Autocomplete with image and text

Question:

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 tried it and it worked perfectly but unfortunately I don't want to load the images from resource drawable as shown in the example, I would like to put the images by bitmap, which are the images I capture by url, so I would like to insert them by bitmap, but unfortunately I have already searched on google and so far I have not been able to find a solution, including here there are 2 posts of a person asking the same thing but apparently didn't have the solution, If anyone can help me I'll be very grateful. Thanks.

Note URL: http://wptrafficanalyzer.in/blog/customizing-autocompletetextview-to-display-images-and-text-in-the-suggestion-list-using-simpleadapter-in-android/

Answer:

I believe that the best way to solve your problem would be to put 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;
}

Then 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 to your needs

I hope it helps

Scroll to Top