0

AdMobを使用してバナーを追加しました。

クリックされたか確認したい。

これは私のコードです:

public class CalcActivity extends Activity {
private AdView adView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calc);
    adView = new AdView(this, AdSize.BANNER, "a150b2362fba949");
    LinearLayout layout = (LinearLayout)findViewById(R.id.calcL);
    layout.addView(adView);
    adView.loadAd(new AdRequest());
}

adView.SetAdListenerメソッドを試しましたが、「OnClick」メソッドがないようです。

何か案が?

ありがとう!

4

3 に答える 3

0

広告の上にビューを配置し、イベントでの伝播を停止せずにonClickListenerを配置しようとしましたか。

編集 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
//Your layout here
<FrameLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.ads.AdView android:id="@+id/adView"
                        android:layout_gravity="bottom"         
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="a150240343d3227"
                         ads:adSize="SMART_BANNER"
                         ads:loadAdOnCreate="true"/>
<View android:layout_width="match_parent" android:id="@+id/myidview"
    android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout>

それがうまくいくかどうかわからない私はテストをしていませんあなたは私が今何を意味するのかわかりますか?クリックリスナーをmyidviewに配置します。

于 2012-11-25T23:13:41.640 に答える
0

アクティビティ ファイル内の広告に関連するすべてのコードを削除し、このコードを対応する xml ファイルに投稿します。

 <com.google.ads.AdView android:id="@+id/adView"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       ads:adUnitId="a150b2362fba949"
                       android:layout_above="@+id/tv1a"
                       ads:adSize="BANNER"
                       ads:loadAdOnCreate="true"/>
于 2013-12-18T11:28:33.223 に答える
-1

まだ方法を知らなかった人のために:

その使用 AdListener

adView.setAdListener(new AdListener() {
            public void onDismissScreen(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Back to app", Toast.LENGTH_SHORT).show();
            }

            public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
               Toast.makeText(BannerAdListener.this, "Error loading", Toast.LENGTH_SHORT).show();

            }

            public void onLeaveApplication(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Left app", Toast.LENGTH_SHORT).show();

            }

            public void onPresentScreen(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Sumthin sumthin", Toast.LENGTH_SHORT).show();

            }

            public void onReceiveAd(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Ad Received", Toast.LENGTH_SHORT).show();

            }
            });
于 2014-09-16T11:56:24.130 に答える