java - Loading icon from URL in MaterialDrawer Android library using Glide -


i'm using materialdrawer lib generate navigation drawer in android, i'm trying image external source , set icon in draweritem object , i'm using glide v4 lib download image external source not sure how update icon placeholders in each , every draweritem have in drawer. here's i've done far:

@override protected void oncreate(bundle savedinstancestate) {     ...      arraylist<idraweritem> draweritems = new arraylist<idraweritem>();     string icon = "http://myiconwebsite.com/myicon.png";      //create drawer item obj     primarydraweritem primary = new primarydraweritem();      //set title     primary.withname("test");     primary.withidentifier(1);     primary.withselectable(false);      //define image view glide     //i'm defining image view can load downloaded image can loaded image drawable     final imageview iv = new imageview(this);      //load image in view     target rb = glide.with(this).asdrawable().load(icon).into(iv);      //get drawable object image view     drawable dr = iv.getdrawable();      //set icon of drawer     primary.withicon(dr);      //add list of drawers     draweritems.add(primary);      //create our drawer     drawerbuilder result = new drawerbuilder();     result.withactivity(this);     result.withdraweritems (draweritems);      ...      result.build();      ...  } 

notice i'm trying download image using glide , load image inside imageview , extract image drawable object using iv.getdrawable(). i'm doing way because need object drawable that's method primary.withicon(dr) accepts in order show icon in drawer. problem when call iv.getdrawable() returns null , doesn't work expected. how achieve that?

also might doing wrong here? saw in documentations mentioned libs glide , picasso can supported didn't add enough examples of how that. bear in mind i'm still new java , glide i'm not sure if that's way it.

any appreciated :) thanks..

i not recommend loading drawable server on ui thread. in addition assume this

target rb = glide.with(this).asdrawable().load(icon).into(iv); drawable dr = iv.getdrawable(); 

will return null @ time of access.

to load icon server normal drawer items, please use drawerimageloader implementation shown in sample profiles (you might need small adjustments v4 glide api changed lot)

for being able load icon server normal items, have add customdraweritem not supported default. sample app has sample implementation can used example:

https://github.com/mikepenz/materialdrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/draweritems/customurlprimarydraweritem.java


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -