2012-11-25 40 views
0

我已經添加了橫幅使用AdMob,想檢查我的橫幅是否被點擊 - 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方法,但它似乎並不有一個「點擊」的方法。

有什麼想法嗎?

謝謝!

+0

檢查此https://stackoverflow.com/questions/9665237/android-admob-on clicklistener/48761987#48761987 – Ninja

回答

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中。

+0

你是什麼意思「放置視圖上面的廣告」?你能舉個例子嗎? – Nadav

+0

Post edited :)告訴我,如果你現在明白了 – jaumard

+0

好吧,我試圖說,但當我嘗試在XML中添加AdView我得到這個:java.lang.NullPointerException 異常詳細信息記錄在窗口>顯示視圖>錯誤日誌和 – Nadav

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"/> 
-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(); 

      } 
      });