Guys I have inserted this code for my adds however they don't show in my app when I test it on my phone. There are no errors in the projects everything is working fine just the adds don't show. Here is my code let me know if you want to see the activity_main.xml as well.
protected void onCreate(Bundle savedInstanceState) {
AppUtils.prepareLoadingDialog(MainActivity.this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeComponents();
initializeListeners();
setViewPagerAdapter();
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ca-app-pub-xxx");
RelativeLayout layout = (RelativeLayout) findViewById(R.id.newAdView);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-xxx");
AdRequest adRequest1 = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
private void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
});
}
private void initializeComponents(){
viewPager = (ViewPager)findViewById(R.id.viewPager);
leftButton = (Button)findViewById(R.id.leftButton);
rightButton = (Button)findViewById(R.id.rightButton);
assignWallpaperButton = (Button)findViewById(R.id.assignWallpaperButton);
}
@SuppressLint("HandlerLeak")
private void initializeListeners(){
leftButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.debug("MainActivity :: left button is clicked");
int currentItem = viewPager.getCurrentItem();
viewPager.setCurrentItem(--currentItem);
}
});
rightButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.debug("MainActivity :: right button is clicked");
int currentItem = viewPager.getCurrentItem();
viewPager.setCurrentItem(++currentItem);
}
});
assignWallpaperButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.debug("MainActivity :: assign wallpaper button is clicked");
try {
int currentItem = viewPager.getCurrentItem();
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
myWallpaperManager.setBitmap(ResourceManager.getWallpaperImage(MainActivity.this, currentItem));
} catch (IOException e) {
Log.debug("MainActivity :: "+e.toString());
Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_LONG).show();
}
}
});
leftButton.setOnTouchListener(new ButtonTouchListener(leftButton));
rightButton.setOnTouchListener(new ButtonTouchListener(rightButton));
}
private void setViewPagerAdapter(){
ImagePagerAdapter adapter = new ImagePagerAdapter(MainActivity.this);
viewPager.setAdapter(adapter);
}
}
Here is my activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity" >
<RelativeLayout
android:id="@+id/newAdView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginBottom="50dp"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"/>
<include
android:id="@+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_medium"
layout="@layout/header" />
<RelativeLayout
android:id="@+id/imageLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/assignWallpaperButton"
android:layout_below="@+id/headerLayout"
android:layout_centerHorizontal="true"
android:layout_marginLeft="@dimen/button_arrow_width"
android:layout_marginRight="@dimen/button_arrow_width"
android:layout_marginTop="1dp"
android:layout_marginBottom="60dp"
android:background="@android:color/transparent" >
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:layout_alignParentBottom="true" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
<Button
android:id="@+id/assignWallpaperButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:background="@color/red_color"
android:text="@string/assingn_wallpaper"
android:textColor="@color/white_color"
android:textSize="@dimen/button_text_size"
android:textStyle="bold" />
<Button
android:id="@+id/leftButton"
android:layout_width="@dimen/button_arrow_width"
android:layout_height="@dimen/button_arrow_height"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/arrow_left" />
<Button
android:id="@+id/rightButton"
android:layout_width="@dimen/button_arrow_width"
android:layout_height="@dimen/button_arrow_height"
android:layout_alignBaseline="@+id/leftButton"
android:layout_alignBottom="@+id/leftButton"
android:layout_alignParentRight="true"
android:background="@drawable/arrow_right" />
</RelativeLayout>
0 comments:
Post a Comment