1
votes

I have an activity GameBoard, inside the activity there is an innerclass named Panel which extends view. I am drawing everything using a canvas to the Panel class. And dynamically changing the content(its a game.) I set my contentView for the GameBoard activity as the Panel View. //inside GameBoard

myView=new Panel(this); setContentView(myView);

I have to add an Ad Which will show while playing. (All play done with the canvas)

I read many documents, found to create a linearlayout and add the layout. and Draw the layout to the canvas.

I tried that. But am getting Ad received. but its not showing.

Please help me to show the Ad to the canvas. Am new to Android. Thanks in advance.

public class GameBoard extends Activity {
private AdView adview;

   protected void onCreate(Bundle savedInstanceState) 
{ 

    super.onCreate(savedInstanceState);

            myView=new Panel(this);
    setContentView(myView);
     }

  public class Panel extends View 
 {

     LinearLayout a = new LinearLayout(getContext());


        public Panel(Context context) 
        {

            super(context);




            a.setPadding(0,50,0,0);


            adview = new AdView(GameBoard.this, AdSize.BANNER,"a14e176c0a170e2");

            AdRequest adRequest = new AdRequest();
            adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

            adview.loadAd(adRequest);

            adview.setVisibility(View.VISIBLE);

            a.addView(adview);


          }










        @Override
        public void onDraw(Canvas canvas) 
        {

            a.draw(canvas);

               // alot other things to draw here
            }




    }

}

1

1 Answers

1
votes

Suggest you

  1. Use XML to define your layout (it will help clarify your understanding)
  2. In your XML definition of your Activity layout have one item being your GameBoard component and another being the AdView