java - Keep image on image view place -


i have 1 fragment , 1 activity.. in layout have 1 image view , 1 button. wrote coding pick image galley cant place image on imageview.. dont konw how do. please 1 fix issue.

my code here:

profilefragment.java

public class profilefragment extends fragment {      private imageview imageview;     private static final int select_photo = 1;      button browseprofilepic;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         sethasoptionsmenu(true);//for option menu          view view = inflater.inflate(r.layout.fragment_layout_profilepic, container,                 false);          imageview = (imageview)view.findviewbyid(r.id.profile_image);         browseprofilepic = (button) view.findviewbyid(r.id.btn_pick);          browseprofilepic.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  intent intent = new intent();                 // show images, no videos or else                 intent.settype("image/*");                 intent.setaction(intent.action_get_content);                 // show chooser (if there multiple options available)                startactivityforresult(intent.createchooser(intent, "select picture"), select_photo);              }         });          return view;     }      @override     public void onactivityresult(int requestcode, int resultcode, intent data) {       //  super.onactivityresult(requestcode, resultcode, data);          if (requestcode == select_photo && resultcode == getactivity().result_ok && data != null && data.getdata() != null) {              uri uri = data.getdata();              try {                 bitmap bitmap = mediastore.images.media.getbitmap(getactivity().getcontentresolver(), uri);                  imageview.setimagebitmap(bitmap);             } catch (ioexception e) {                 e.printstacktrace();             }         }     }      @override     public void oncreateoptionsmenu(menu menu,menuinflater inflater ) {         super.oncreateoptionsmenu(menu, inflater);         // inflate menu; adds items action bar if present.         inflater.inflate(r.menu.menu_profile_pic, menu);     }     @override     public boolean onoptionsitemselected(menuitem item) {         // handle presses on action bar items         switch (item.getitemid()){             case r.id.action_done:                 toast.maketext(getactivity().getapplicationcontext(), "sa", toast.length_long).show();          }         return super.onoptionsitemselected(item);      }      } 

mainactivity.java:

@override     public void onactivityresult(int requestcode, int resultcode, intent data) {      } 

if activity hosting fragment overrides onactivityresult mainactivity make sure calls super.onactivityresult (there's no need remove override), should give fragment chance handle result see, otherwise assumes mainactivity.java handled result , won't call fragment onactivityresult

if image won't show first confirm onactivityresult not being called placing toast on beginning of fragment onactivityresult place result here , work there

also dont: getactivity().result_ok use activity.result_ok

edit: tested out code , calling super.onactivityresult expected works perfect, , won't work without it


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -