how to add admob to tabbed activity ?

611 views
Skip to first unread message

bana w bas

unread,
Apr 25, 2017, 6:06:25 AM4/25/17
to Google Mobile Ads SDK Developers
i started my project with empty activity that was the main_activity then i added a tabbed activity then i deleted the main one so after i finished making my project i tryed every way to put admob and and build app and try it on my phone and it doesnt show anything




this is java file .

public class tap extends AppCompatActivity {


private static final String TAG = "tap";

private SectionsPageAdapter mSectionsPageAdapter;
private ViewPager mViewPager ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tap);
Log.d(TAG, "onCreate : starting");
mSectionsPageAdapter = new SectionsPageAdapter(getSupportFragmentManager());

// Set up the ViewPager with the section adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
setupViewPager(mViewPager);
TabLayout tablayout = (TabLayout) findViewById(R.id.tabs);
tablayout.setupWithViewPager(mViewPager);
}
private void setupViewPager(ViewPager viewPager) {
SectionsPageAdapter adapter = new SectionsPageAdapter(getSupportFragmentManager());
adapter.addFragment(new pharmacist(),"Ph");
adapter.addFragment(new dentist(),"Dent");
adapter.addFragment(new doctor(),"MD");
adapter.addFragment(new pook(),"on");
viewPager.setAdapter(adapter);

}
}

this is the layout


<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.testpharmacist.tap">


<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">


<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="50dp"
android:layout_height="25dp"
android:layout_marginTop="10dp"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">

</android.support.v7.widget.Toolbar>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways" />

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>







Deepika Uragayala- MobileAds SDK team

unread,
Apr 25, 2017, 3:12:16 PM4/25/17
to Google Mobile Ads SDK Developers
Hi,

I would suggest that you checkout our RecyclerView sample app, which demonstrates how to insert AdViews dynamically into a List. This should help you with your ViewPager too.

I could also see that you have opened a new post with the same concerns. So, I will answer your questions in this post and we will continue the discussion here. 

Let me answer your other questions here :

1-i finished making my project i tried every way to put admob and
build app and try it on my phone and it doesn't show the ad can any one help me .
 
If Ads are not being served in your app, there might be several reasons for this and I would suggest that you contact our Admob Product Support Team as our team deals with only SDK related queries.

2. where to add the banner is it in the tabbed activity only or in
the fragments and in the other activities that contain pdf viewer and web view ??

This is a placement/policy query and I would suggest that you go through our best practices guidelines or use the AdMob Help Center to get more information.

Let me know if you have any other questions. I will be happy to assist you.

Regards,
Deepika Uragayala
Mobile Ads SDK Team

bana w bas

unread,
Apr 26, 2017, 3:20:22 AM4/26/17
to Google Mobile Ads SDK Developers
-if i didn't yet publish my app will this effect that ads doesn't appear ?
-----and if i add the ad on the main tabbed activity will it stay visible when activity open by buttons from the fragments or will i have to add them to those activities individually ?
----- i am sorry but this is my first coding experience so i am new to all this and i finished my app with no problem until now only the admob what took more time than making my entire app , thank you for your reply and i hope that you could help me.
 

Deepika Uragayala- MobileAds SDK team

unread,
Apr 26, 2017, 1:56:57 PM4/26/17
to Google Mobile Ads SDK Developers
Hi,

"-if i didn't yet publish my app will this effect that ads doesn't appear ?"

This would not impact the ads from being served. We do recommend that you enable test ads when making the ads request until your application goes into production.

"-----and if i add the ad on the main tabbed activity will it stay visible when activity open by buttons from the fragments or will i have to add them to those activities individually ?"

This should work but again it is dependent on your implementation. If the Fragment is not hovering over the parent Activity, then having one ad view through out the flow must work. You can send us your sample app and I would certainly be able to help you further.

Regards,
Deepika Uragayala
Mobile Ads SDK Team


Message has been deleted

bana w bas

unread,
Apr 26, 2017, 2:26:08 PM4/26/17
to Google Mobile Ads SDK Developers
i already posted my main activity this is one out of four of the fragments 

this is java file 
package com.testpharmacist:
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Spinner;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

import static com.testpharmacist.R.id.container;

public class pharmacist extends Fragment {
private static final String TAG = "pharmacist";

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.pharmacist,container,false);

Button newPage = (Button) view.findViewById(R.id.t1);
newPage.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question1.class);
startActivity(intent);
}
});
Button newPage1 = (Button) view.findViewById(R.id.t2);
newPage1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question2.class);
startActivity(intent);
}
});
Button newPage2 = (Button) view.findViewById(R.id.t3);
newPage2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question3.class);
startActivity(intent);
}
});
Button newPage3 = (Button) view.findViewById(R.id.t4);
newPage3.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question4.class);
startActivity(intent);
}
});
Button newPage4 = (Button) view.findViewById(R.id.t5);
newPage4.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question5.class);
startActivity(intent);
}
});
Button newPage5 = (Button) view.findViewById(R.id.t6);
newPage5.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question6.class);
startActivity(intent);
}
});
Button newPage6 = (Button) view.findViewById(R.id.t7);
newPage6.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), question7.class);
startActivity(intent);
}
});
Button newPage7 = (Button) view.findViewById(R.id.t8);
newPage7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), drugbank.class);
startActivity(intent);
}
});

return view;
}
}


-------------------------------------



and this is the layout :


<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="650dp"
android:background="@color/one" >

<LinearLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:myapp="http://schemas.android.com/apk/res/com.testpharmacist"
android:background="@color/one" >

<TextView
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:textSize="22sp"
android:textStyle="bold"
android:text="All what Pharmacists need"
android:fontFamily="sans-serif-smallcaps"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:textColor="@color/three"
android:layout_height="wrap_content" />
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:layout_marginTop="7dp"
android:id="@+id/t1"
android:text="Summarized"
android:textSize="25sp"
android:textAllCaps="false"
android:layout_gravity="center"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="6dp"/>
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t2"
android:text="Summarized1"
android:textSize="25sp"
android:textAllCaps="false"
android:layout_gravity="center"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="6dp"/>
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t5"
android:text="Summarized2"
android:textSize="25sp"
android:layout_gravity="center"
android:textAllCaps="false"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_height="40dp"
android:layout_width="200dp"
android:layout_marginBottom="6dp"/>
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t3"
android:text="Questions"
android:textSize="25sp"
android:textAllCaps="false"
android:layout_gravity="center"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="6dp" />
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t4"
android:text="Questions1"
android:textSize="25sp"
android:layout_gravity="center"
android:textAllCaps="false"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="6dp" />
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t7"
android:text="Questions2"
android:textSize="25sp"
android:layout_gravity="center"
android:textAllCaps="false"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="6dp"/>
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t6"
android:text="Calculation"
android:textSize="25sp"
android:textAllCaps="false"
android:layout_gravity="center"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="6dp"/>
<Button
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold"
android:id="@+id/t8"
android:text="Best Online reference"
android:textSize="27sp"
android:layout_gravity="center"
android:textAllCaps="false"
android:background="@drawable/rounded"
android:textColor="@color/new_colors"
android:layout_width="250dp"
android:layout_height="wrap_content"/>


</LinearLayout>

</android.support.v4.widget.NestedScrollView>

Deepika Uragayala- MobileAds SDK team

unread,
Apr 26, 2017, 5:15:17 PM4/26/17
to Google Mobile Ads SDK Developers
Hi,

You can look at our Banner app implementation and just add that in your activity if you want to have one AdView throughout its lifecycle. You don't need to add anything in your Fragment. If you are still facing the issues then send me a sample app and I would be able to help you further.

You can also take a look at this post at StackOverflow for additional information.

Regards,
Deepika Uragayala
Mobile Ads SDK Team

bana w bas

unread,
Apr 27, 2017, 4:24:19 AM4/27/17
to Google Mobile Ads SDK Developers
i am sorry cuz i am new at developing apps how do i make a sample app ?

bana w bas

unread,
Apr 27, 2017, 5:28:17 AM4/27/17
to Google Mobile Ads SDK Developers
i used the sample you quoted from github and the app crashed and didn't open.

Chris Feldman (Mobile Ads SDK Team)

unread,
Apr 27, 2017, 3:03:07 PM4/27/17
to Google Mobile Ads SDK Developers
Hi Bana,

I'd like to stress that this is not the type of issue that we normally support on this forum. In the future, you'll have to look for help on StackOverflow or elsewhere for similar implementation issues. That being said, I had some time so I added an adView to the standard Android Studio 'Tabbed Activity'. You can download the project here. The code follows our Get Started guide for Android. The only difference being that the AdView is placed on top of a ViewPager. This implementation will show the same ad on each fragment. If you want each fragment to have its own ad, you will have to adapt the code.

Regards,
Chris Feldman
Mobile Ads SDK Team
Reply all
Reply to author
Forward
0 new messages