Image and text autocomplete

Asked

Viewed 79 times

3

I’d like to make a 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, I tested and worked perfectly but unfortunately I do not want to load the images from drawable Resource as in the example, I would like to put the images by bitmap that are the images I capture by url, so I would like to insert by bitmap but unfortunately I already searched on google and so far I could not find a solution, Even here are 2 posts 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: http://wptrafficanalyzer.in/blog/customizing-autocompletetextview-to-display-images-and-text-in-the-suggestion-list-using-simpleadapter-in-android/

1 answer

0

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 take 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;
}

So 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, adapite it as per your need

hope it helps

  • Oops, Thank you very much for the attention but that’s not what I need, I already have the images in bitmap array, I need to put in the autocomplete the images ... In this link above has exactly what I want to do but it is inserting the images by drawable Resource I have the bitmap array and I want to insert from bitmap, as they will be images that I will receive from the url.

  • ok, so, but taking the images from the array and converting them to drawable is the same as taking images by Resource drawable

  • I’ve tried this way, converting the images to drawable and even then it didn’t work because in the "put" there it loads the images by Resource and not drawable ... In the link the example shows the images in drawable porem in Resource so even converting does not work!.

  • put your code so I can look

Browser other questions tagged

You are not signed in. Login or sign up in order to post.