Reputation: 4807
I managed to use drawable image into my listview, but how can I do the same with image from SD card?
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("KEY_IMAGE", Integer.toString(R.drawable.a)); //change to SD card
map.put("KEY_LINK", "link");
map.put("KEY_NAME", "name");
menuItems.add(map);
String[] from = { "KEY_IMAGE", "KEY_NAME", "KEY_LINK" };
int[] to = {R.id.imageView_cell, R.id.list_headline,R.id.list_info };
SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), menuItems, R.layout.list_view,from, to);
listview.setAdapter(adapter);
Upvotes: 0
Views: 212
Reputation: 4126
You can do this without implementing a custom adapter.
You should implement the SimpleAdapter.ViewBinder
interface, and invoke setViewBinder()
to tell your adapter how to bind the data.
As mentioned by LordRaydenMK, it's good practice to load the images asynchronously (e.g. using Picasso), inside your implementation of setViewValue()
.
Upvotes: 1
Reputation: 13321
You will have to create a custom adapter and override the getView
method. You can find an example here using the best practices for view recycling and View holders.
Loading images, especially in adapters should be done in a background thread so it doesn't slow down the UI.
For background loading you can use a library like Picasso.
Picasso.with(context).load(new File(...)).into(imageView2);
Upvotes: 0