Admob横幅广告未在SherlockFragmentActivity中加载

时间:2013-10-03 15:54:23

标签: android actionbarsherlock admob

我尝试在SherlockFragmentActivity中加载Admob横幅广告。它没有加载。但是,当我尝试使用appflood横幅广告时,它确实有效。

我尝试使用最新的Admob SDK 6.4.1,然后尝试使用较旧的SDK 6.2.1,但我无法获得任何结果。日志中没有记录错误。

以下是我的代码:

public class SampleClass extends SherlockFragmentActivity {
private ViewPager _mViewPager;
private ViewPagerAdapter _adapter;
private AdView adView = null;   
private boolean adShown = false;

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
        setContentView(R.layout.main);
        setUpView();
        setTab();
        _mViewPager.setCurrentItem(1);     
    this.adShown = false;               
        AdUpdate();
 }

private void setUpView(){
     _mViewPager = (ViewPager) findViewById(R.id.viewPager);
     _adapter = new     ViewPagerAdapter(getApplicationContext(),getSupportFragmentManager());
     _mViewPager.setAdapter(_adapter);
     _mViewPager.setCurrentItem(1);     
}

private void setTab() {
_mViewPager.setOnPageChangeListener(new OnPageChangeListener(){                     


@Override
public void onPageScrollStateChanged(int position) 

{}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) 

{}

@Override

public void onPageSelected(int position) 

{           

switch(position) { 

case 0:                             
findViewById(R.id.firstTab).setVisibility(View.VISIBLE);
findViewById(R.id.secondTab).setVisibility(View.INVISIBLE);
break;
case 1:                             


findViewById(R.id.firstTab).setVisibility(View.VISIBLE);

findViewById(R.id.secondTab).setVisibility(View.INVISIBLE);

break;

}

}                       

});     

}


public void AdUpdate()

{

        if(!this.adShown)

        {

            this.adShown = true;        

            this.adView = new AdView(this, AdSize.SMART_BANNER, MY_ID);

            AdRequest adRequest = new AdRequest();          

            RelativeLayout.LayoutParams params = new 

                RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 

                RelativeLayout.LayoutParams.WRAP_CONTENT);      

                params.addRule(RelativeLayout.ALIGN_PARENT_TOP);

                _mViewPager.addView(adView, params);

                adView.loadAd(adRequest);

/*
Following code also didn't work for Admob banner ads. But it worked for appflood banner ads.
RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.l1root);      

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);       

params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

relativeLayout.addView(adView, params);
*/

}
}



///Code for Layout Fragment

public class LayoutOne extends Fragment 
{

    public static Fragment newInstance(Context context) 
        {

        LayoutOne f = new LayoutOne();

        return f;

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
{

        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.layout_one, null);



        return root;

    }   
}

1 个答案:

答案 0 :(得分:0)

请您分享您的Log cat视图,以便我们可以确定问题的实际位置......如果我没有错,那么您可能会花时间在您的应用程序中显示添加...