1

In the market I saw an app is displaying admob in the alert dialog . after I reading this and this and this ,

I still can't figure out how to display the ads in alert dialog same like the one below. (or any others method , that can display the ads in a alert dialog)

enter image description here

I've been scratching my head trying to figure out how to do that.

Could anyone be kind enough to guide me through how to go about this?

XML :

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@id/tablayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:myapp="http://schemas.android.com/apk/res/com.xxx.xxx">

    <TableRow>
  <com.admob.android.ads.AdView android:id="@id/myad" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  myapp:backgroundColor="#ff000000" 
  myapp:primaryTextColor="#ffffffff" 
  myapp:secondaryTextColor="#ffcccccc" />
    </TableRow>

</TableLayout>

Java :

 public void onBackPressed() {
    //set up dialog
                Dialog dialog = new Dialog(main.this);
                dialog.setContentView(R.layout.exitdialog);
                dialog.setTitle("This is my custom dialog box");
                dialog.setCancelable(true);


                //set up button
                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                //now that the dialog is set up, it's time to show it    
                dialog.show();
            }
        });
}

Thanks.

Community
  • 1
  • 1
xDragonZ
  • 12,502
  • 6
  • 37
  • 52

2 Answers2

2

I found another solution to do this.

AdMob offers a JavaScript integration solution for Android and iPhone sites/web apps.

Instead of using XML and a custom dialog. We can use Admob web ads and a HTML that contain the admob code and load it with webview in the dialog.

xDragonZ
  • 12,502
  • 6
  • 37
  • 52
0

I believe it's not possible unless you're on landscape mode. The reason is that the ad needs something close to the device width (in portrait mode, e.g. 480) for the ad, so it is only available in landscape mode when you're adding it inside a dialog

IncrediApp
  • 10,303
  • 2
  • 33
  • 24
  • Yes, I just read somewhere it say admob only display ads on landscape mode when using alert dialog , but now the problem is I can't add the ads in the dialog . Do you have any idea how to do it? – xDragonZ Oct 03 '11 at 10:07
  • Haven't done it myself, but I assume that if you force landscape mode when loading the alert dialog (setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);) and then load the ad, it should show – IncrediApp Oct 03 '11 at 10:17
  • Can you help me or tell me the result ? I have try for few hours ready , I still can't make it working. Thanks – xDragonZ Oct 03 '11 at 10:22