세 개의 탭이있는 탐색 모음이 있습니다. 각 탭은 조각입니다. 이제 두 번째 탭을 클릭하면 삽입 광고가 나옵니다. 그럼 광고를 어디에로드해야합니까? 그리고 광고를 어디에서 보여야합니까?전면 광고를 어떻게 표시합니까?
내 MainActivity :
public class MainActivity extends AppCompatActivity{
public MediaPlayer mp;
NavigationView mNavigationView;
FragmentManager mFragmentManager;
FragmentTransaction mFragmentTransaction;
public InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
AdRequest adRequest = new AdRequest.Builder().build();
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd = new InterstitialAd(getContext());
mInterstitialAd.setAdUnitId("ca-app-pub-9756227769488050/2954649723");
mInterstitialAd.loadAd(adRequest);
}
내 secondFragment :
public class SecondFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView=inflater.inflate(R.layout.second_layout,container,false);
return rootView;
}
그리고 (내가 그 중요한 경우 몰라요) 내 TabFragment : 내가 말을해야 할
public class TabFragment extends Fragment {
public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 3 ;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/**
*Inflate tab_layout and setup Views.
*/
View x = inflater.inflate(R.layout.tab_layout,null);
tabLayout = (TabLayout) x.findViewById(R.id.tabs);
viewPager = (ViewPager) x.findViewById(R.id.viewpager);
/**
*Set an Apater for the View Pager
*/
viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
/**
* Now , this is a workaround ,
* The setupWithViewPager dose't works without the runnable .
* Maybe a Support Library Bug .
*/
tabLayout.post(new Runnable() {
@Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
return x;
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
/**
* Return fragment with respect to Position .
*/
@Override
public Fragment getItem(int position)
{
if(position == 0){
return new FirstFragment();
}
if(position == 1){
return new SecondFragment();
}
if(position == 2){
return new ThirdFragment();
}
return null;
}
@Override
public int getCount() {
return int_items;
}
/**
* This method returns the title of the tab according to the position.
*/
@Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0 :
return "first";
case 1 :
return "second";
case 2 :
return "third";
}
return null;
}
}
});
}
}
그래서 showInterstitial()
?
final public void showInterstitial(){
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
if(mInterstitialAd.isLoaded()){
mInterstitialAd.show();
}
}
@Override
public void onAdClosed() {
}
Im이 문제에 대해 한 달 이상 걸려 있으니 자세히 설명해주세요. 감사합니다
가능한 복제 [이 경우에 올바르게 삽입 광고를 표시하는 방법?] (http://stackoverflow.com/questions/43141684/how-to-show-interstitial-ad-correctly-in-this- 케이스) – William