android - Load a remote image in a MenuItem using Glide -
usually if want load image glide write following:
glide.with(context) .load(theurloftheimage) .error(r.drawable.ic_error_image) .into(theimageview);
but if need load image of url menuitem has changed in real time?
the following not possible because method into
not accept parameter:
@override public boolean onprepareoptionsmenu(menu menu) { menuitem settingsitem = menu.finditem(r.id.actionbar_menu_profile_actions); if (changeimage) { glide.with(this).load(theurloftheimage).error(r.drawable.ic_error_image).into(settingsitem); } return super.onprepareoptionsmenu(menu); }
using approach suggested in responses this question worked
@override public boolean onprepareoptionsmenu(menu menu) { menuitem settingsitem = menu.finditem(r.id.actionbar_menu_profile_actions); if (changeimage) { glide.with(this).load(theurloftheimage).asbitmap().into(new simpletarget<bitmap>(100,100) { @override public void onresourceready(bitmap resource, glideanimation glideanimation) { settingsitem.seticon(new bitmapdrawable(getresources(), resource)); } }); } return super.onprepareoptionsmenu(menu); }
Comments
Post a Comment