Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-AdMob将广告设置为“消失”?_Android - Fatal编程技术网

Android-AdMob将广告设置为“消失”?

Android-AdMob将广告设置为“消失”?,android,Android,我想问,如何为Admob实现AdListner。如果点击了广告,我想让它消失。 我试过了,但没用 final AdView ad1 = (AdView) findViewById(R.id.ad1); ad1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method

我想问,如何为Admob实现AdListner。如果点击了广告,我想让它消失。 我试过了,但没用

final AdView ad1 = (AdView) findViewById(R.id.ad1);
        ad1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                ad1.setVisibility(View.GONE);
                ad1.destroy();          }
        });

谢谢。

根据您所在的设备,您可能需要使用该视图的invalidate()方法。(我会注意到我需要在2.1设备上的freewheel上做一些广告)

--或--
尝试将ad1视图放置在包装器视图(LinearLayout或其他小视图)中,然后将该包装器视图的可见性设置为view.GONE

我认为AsAdview是相对年轻的,所以你需要

 * ad1.setClickable(true);


如果仍有人在搜索此文件,以下是我使用的代码:

public  class myActivity extends Activity implements AdListener{
    /** Called when the activity is first created. */


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


         AdView adView = (AdView)this.findViewById(R.id.ads2);
         adView.setAdListener(this);
        adView.loadAd(new AdRequest());





    }

    public void onDismissScreen(Ad arg0) {
        RelativeLayout rellayout = (RelativeLayout) findViewById(R.id.rellayout);
        AdView adView = (AdView)this.findViewById(R.id.ads2);
        rellayout.removeView(adView);
    }

    public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
        // TODO Auto-generated method stub

    }

    public void onLeaveApplication(Ad arg0) {
        // TODO Auto-generated method stub

    }

    public void onPresentScreen(Ad arg0) {
        // TODO Auto-generated method stub

    }

    public void onReceiveAd(Ad arg0) {
        // TODO Auto-generated method stub

    }

}
public  class myActivity extends Activity implements AdListener{
    /** Called when the activity is first created. */


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


         AdView adView = (AdView)this.findViewById(R.id.ads2);
         adView.setAdListener(this);
        adView.loadAd(new AdRequest());





    }

    public void onDismissScreen(Ad arg0) {
        RelativeLayout rellayout = (RelativeLayout) findViewById(R.id.rellayout);
        AdView adView = (AdView)this.findViewById(R.id.ads2);
        rellayout.removeView(adView);
    }

    public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
        // TODO Auto-generated method stub

    }

    public void onLeaveApplication(Ad arg0) {
        // TODO Auto-generated method stub

    }

    public void onPresentScreen(Ad arg0) {
        // TODO Auto-generated method stub

    }

    public void onReceiveAd(Ad arg0) {
        // TODO Auto-generated method stub

    }

}