質問

My main activity calls my Surfaceview game, setting a layout with an adview and surfaceview added (initially I did not use a layout at all before I had to ad the banner). however I have not been able to access the main activity from surfaceview to change the layout so it doesn't include the adview once the game starts. i'm forced to have the banner on continually because of this. attempts to kill the ad still leaves a blank banner. does anyone know how to access main activity functions from surfaceview.

I created a removead() function in the main activity to define a new contextview without the adView, but I can't access it.

context, the main activity, is passed to the Surfaceview on creation. I've tried:

context.removead();
this.getContext().removead();
((Activity) this.getContext()).removead();
ViewGroup vg = (ViewGroup)(
this.getParent());
vg.removeView(adView);
役に立ちましたか?

解決

I ended up abandoning attempts to control the adAiew directly from surfaceView, instead creating a Handler in the main activity and sending messages to it from the surfaceView the main activity created. The handler then calls VISIBLE or GONE to the adAiew depending on the message sent.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top