私は現在、クリックで多種多様な日常の音を再生することを目的としたAndroidアプリケーションを開発しています。
私には 3 つの活動があります: ホーム、アニモー、トランスポートです。
Homeは問題なく、animauxも問題ありません (すべてのサウンドを問題なく再生します)。しかし、トランスポート
アクティビティ
に admob を統合したいと考えています。広告はうまく表示されますが、サウンド ボタンを押しても何も起こりません。私の間違いとその修正方法を理解していただけると助かります。
ここに transports.java があります
public class Transports extends Activity {
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transports);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "xxxxxx"
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout1);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
private MediaPlayer mPlayer = null;
/** Called when the activity is first created. */
public void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transports);
Button btn_sound_sncf2 = (Button) findViewById(R.id.sncfnew);
btn_sound_sncf2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
playSound(R.raw.sncf2);
}
});
Button btn_sound_sncf1 = (Button) findViewById(R.id.sncf1);
btn_sound_sncf1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
playSound(R.raw.sncf1);
}
});
}
@Override
public void onPause() {
super.onPause();
if(mPlayer != null) {
mPlayer.stop();
mPlayer.release();
}
}
private void playSound(int resId) {
if(mPlayer != null) {
mPlayer.stop();
mPlayer.release();
}
mPlayer = MediaPlayer.create(this, resId);
mPlayer.start();
}
}
そしてここに transports.xml コードがあります:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Transports" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
android:gravity="top" >
</com.google.ads.AdView>
<Button android:id="@+id/sncfnew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/sncf1"
android:layout_below="@+id/sncf1"
android:layout_marginTop="38dp"
android:text="@string/sncfnew" />
<Button android:id="@+id/sncf1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/linearLayout1"
android:layout_below="@+id/linearLayout1"
android:text="@string/sncf1" />
</LinearLayout>
</RelativeLayout>
問題が私の xml ファイルにないのだろうか : admob が必要とする linearlayout との明確なインターフェイスを作成するのに多くの困難があります。