Monday, 15 June 2015

java - How to show PopUpWindow after it has been inflated -



java - How to show PopUpWindow after it has been inflated -

i have popupwindow needs load activity starts, uses displaymetrics of screen, other things. however, getting error "unable add together window -- token null not valid; activity running?" line welcome.showatlocation(popupview2, gravity.center, 0, 0);.

how can have popupwindow shown when resources have been retrieved? popupwindow acts splash (so can fade out instantly onclick), window must first thing user sees.

my code:

@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); layoutinflater inflater = (layoutinflater) .getsystemservice(context.layout_inflater_service); displaymetrics displaymetrics = getresources().getdisplaymetrics(); dpwidth = displaymetrics.widthpixels / displaymetrics.density; dpheight = displaymetrics.heightpixels / displaymetrics.density; popupview2 = inflater.inflate(r.layout.start_layout, null); welcome = new popupwindow(popupview2, (int) dpwidth, (int) dpheight); welcome.setanimationstyle(r.style.animation2); welcome.showatlocation(popupview2, gravity.center, 0, 0); }

basically, there sort of "onresourcesloaded"-like thing can use? help appreciated.

when code invoked scheme not ready measure metrics

move code method :

@override public void onattachedtowindow() { // todo auto-generated method stub super.onattachedtowindow(); }

this method invoked when metrics can used because activity displayed.

java android android-popupwindow

No comments:

Post a Comment