When to setImageBitmap during creation of Fragment in Android? -



When to setImageBitmap during creation of Fragment in Android? -

i need setimagebitmap during creation of fragment. cannot in oncreate, because imageview not initialized yet. had same problem in activity, called onwindowfocuschanged method , worked. there no such method in fragment. how should solve this? tried

@override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); string imgpath = day.getphotopath(); if (imgpath != null) { dayphoto.setimagebitmap(photoutils.decodesampledbitmapfromfile(dayphoto, imgpath)); } }

but gives no results. fragment blank

@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_day, container, false); sethasoptionsmenu(true); dayphoto = (imageview) rootview.findviewbyid(r.id.dayimage); homecoming rootview; }

so needed utilize globallayout create work :

viewtreeobserver vto = rootview.getviewtreeobserver(); vto.addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { string imgpath = day.getphotopath(); if (imgpath != null) { dayphoto.setimagebitmap(photoutils.decodesampledbitmapfromfile(dayphoto, imgpath)); viewtreeobserver obs = rootview.getviewtreeobserver(); obs.removeglobalonlayoutlistener(this); } } });

android android-fragments imageview

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -