N
N
nikita0710032020-05-03 15:02:51
Java
nikita071003, 2020-05-03 15:02:51

How to add image and text to listview?

I need the name of the helicopter and its image to be displayed in the leaves. I get everything from the database (name - text, picture - its url)
Please help me adapt my code so that it can also display pictures in the listview by their url, and not just text (or, if my code is really bad, suggest another option)

There is a SimpleAdapter that displays only the names:

R.id.listviewModel - TextViev
R.id.listviewImage - ImageView (did not use it in the code)
hl_model - String "Helicopter model", loaded from the database
HL_MODEL - static String "helicopter_model"
hl_image - String "image url" (didn't use it either)

arraylist = new ArrayList<HashMap<String, Object>>();
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {

                ListAdapter listAdapter = new SimpleAdapter(show_transportActivity.this, arraylist, R.layout.activity_listitem, new String[] {HL_MODEL},
                        new int[] {R.id.listviewModel});
                listViev = (ListView) findViewById(R.id.showtranspotrListView);
                listViev.setAdapter(listAdapter);
            }

        };


Everything is loaded into the adapter like this:

HashMap<String, Object> Hashmap = new HashMap<String, Object>();
                        Hashmap.put(HL_MODEL, hl_model);
                        arraylist.add(Hashmap);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-05-04
@zagayevskiy

Use Glide.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question