2011-07-20 3 views
0

Impossible de comprendre celui-ci. J'ai cinq boutons et le 5ème je veux montrer ma publicité d'AdMob mais cela ne fonctionnera tout simplement pas. Je suis si proche! Toute aide appréciée. Ci-dessous mon activity.java et mon main.xmlbouton android admob

package com.CompanyName.SANDBOX; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import com.google.ads.*; 

public class SANDBOXActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main); 

    //--> Create the adView 
    AdView adView = new AdView(this, AdSize.BANNER, "a14e27391701ceb"); 
    // Lookup your LinearLayout assuming it’s been given 
    // the attribute android:id="@+id/mainLayout" 
    Button btn5 = (Button)findViewById(R.id.btn_Button05); 
    // Add the adView to it 
    btn5.addView(adView); 
    // Initiate a generic request to load it with an ad 
    adView.loadAd(new AdRequest()); 
    //--> End AdMoB adView 
} 
} 

et mon main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:focusableInTouchMode="true" 
    android:orientation="vertical" 
    android:gravity="center_vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/icon" 
    android:scaleType="centerInside"> 
<Button android:id="@+id/btn_Button01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textStyle="bold" 
    android:text="Start SANDBOX Mobile"> 
</Button> 
<Button android:id="@+id/btn_Button02" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textStyle="bold" 
    android:text="More Applications"> 
</Button> 
<Button android:id="@+id/btn_Button03" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textStyle="bold" 
    android:text="Share"> 
</Button> 
<Button android:id="@+id/btn_Button04" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:text="Send feedback"> 
</Button> 
<Button android:id="@+id/btn_Button05" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_gravity="center_horizontal"> 
</Button> 
</LinearLayout> 
+0

Quelle erreur recevez-vous? – Pengume

+0

pas d'erreur du tout, il n'affiche tout simplement pas d'annonce de tout type –

+0

Etes-vous sûr de vouloir avoir la permission d'accéder à internet? – Pengume

Répondre

0
AdView adview = (AdView)findViewById(R.id.adView1); 
AdRequest re = new AdRequest(); 
re.setTesting(true); 
adview.loadAd(re); 

probablement essayer d'importer ceux-ci, espérons qu'il aide. Vous devez le faire pour votre application. Je ne pouvais pas le faire aussi d'abord :)

+0

"Quand vous dites essayer d'importer ceux-ci", Que voulez-vous dire? Je crois que j'ai peut-être découvert le problème réside avec AdMob. Apparemment, il y a un bug important dans la version AdMob qui vient de sortir LIVE to PRODUCTION le 19 juillet! Le pot admob est seulement environ 50K et le .zip lui-même ne contient pas les instructions ou pdf. Voir l'URL suivante. https://groups.google.com/forum/#!topic/google-admob-ads-sdk/Ys6CsvTez3I. Personnellement, j'ai déjà mis environ 25 heures à tenter de résoudre le problème. –

1

Il n'y a pas de méthode addView (AdView) pour Button.Change le bouton à une mise en page.

LinearLayout layout = (LinearLayout)findViewById(R.id.lout); 
// Create the adView 
    final AdView adView = new AdView(this, AdSize.BANNER, "a14e27391701ceb"); 
    // Add the adView to it 
layout.addView(adView); 

// Initiate a generic request to load it with an ad 
AdRequest request = new AdRequest(); 

request.setTesting(true); 
adView.loadAd(request);