android - Navigate to Fragment which is not in current Activity -
i use code here create flip card animation older android devices. want flip fragment not in current activity. tried code:
myfragment f = new myfragment(); getactivity().getsupportfragmentmanager().begintransaction().add(r.id.item_detail_container, f).commit(); getactivity().getsupportfragmentmanager().executependingtransactions(); f.getview().setvisibility(view.gone); view root = getactivity().getwindow().getdecorview().findviewbyid(android.r.id.content); flipanimation flipanimation = new flipanimation(this.getview(), f.getview()); root.startanimation(flipanimation);
but comes nullpointerexception on toview.setvisibility(view.visible);
in flipanimation class. how can flip fragment not in current activity?
edit: solve question answer 1 , comments it. code here updated , works fine now.
commit()
on fragmenttransaction
not immediate. asynchronous. hence, time commit()
returns, fragment has not been called oncreateview()
yet, , therefore getview()
returns null
.
i think right answer applying animations right in fragmenttransaction
via setcustomanimations()
.
beyond that, try post()
work flipanimation
, occurs after transaction has been completed.
Comments
Post a Comment