黑莓广告横幅点击

时间:2011-08-17 08:11:31

标签: blackberry

如何在黑莓横幅广告中添加点击事件。 这是我的代码:

public class DemonstrationScreen extends MainScreen 
{  
    public DemonstrationScreen()
    {
      final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");
      Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder);
      bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
      VerticalFieldManager vfm = new VerticalFieldManager
                                 (VerticalFieldManager.NO_VERTICAL_SCROLL
                                 | VerticalFieldManager.NO_VERTICAL_SCROLLBAR
                                 | VerticalFieldManager.USE_ALL_WIDTH);
      HorizontalFieldManager hfm = new HorizontalFieldManager
                                 (HorizontalFieldManager.FIELD_HCENTER
                                 | HorizontalFieldManager.FIELD_VCENTER);
      hfm.add(bannerAd);
      vfm.add(hfm);
      add(vfm);

      FieldChangeListener listener=new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {

                if(field==bannerAd){
                    Dialog.alert("Banner clicked");
                }
            }};
            bannerAd.setChangeListener(listener);

    }  
}

这不起作用。当我点击广告时,它没有显示任何内容。

1 个答案:

答案 0 :(得分:1)

我认为这是Banner的意外/不当使用。

但是,您可以通过在navigationClick()覆盖Banner来实现此目的:

public class DemonstrationScreen extends MainScreen 
{  
    public DemonstrationScreen()
    {
      final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");
      Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder) {
          protected boolean navigationClick(int status, int time) {
              Dialog.alert("Banner clicked");
              return super.navigationClick(status, time);
          }
      };
      bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
      VerticalFieldManager vfm = new VerticalFieldManager
                                 (VerticalFieldManager.NO_VERTICAL_SCROLL
                                 | VerticalFieldManager.NO_VERTICAL_SCROLLBAR
                                 | VerticalFieldManager.USE_ALL_WIDTH);
      HorizontalFieldManager hfm = new HorizontalFieldManager
                                 (HorizontalFieldManager.FIELD_HCENTER
                                 | HorizontalFieldManager.FIELD_VCENTER);
      hfm.add(bannerAd);
      vfm.add(hfm);
      add(vfm);
    }  
}

但是由于RIM取得Banner级决赛,你无法做到这一点。所以我认为你的要求没有简单的解决方案。一个难的解决方案是"弄清楚"在MainScreen级别点击了哪个字段(navigationClick MainScreen,您可以查看哪个字段是焦点并执行smth。)