Title: Phone won't play the on-click sound
Tags: java;android;audio;onclicklistener
Question: I am currently developing an android application in which purpose is to play a large variety of every-day sounds on click.

I have 3 activities : home, animaux and transports.
Home is fine, animaux is fine (it plays all the sounds without any problems).
But I want to integrate admob on Transports acivity. Ads display well, but when I cluck on the sounds buttons, nothing happens. If you could help me understand my mistake and how to fix it, it would be very nice !

Here is 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();
    }
}
```

And here is the transports.xml code :

```<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" &gt;

<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" &gt;

    <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" &gt;
    </com.google.ads.AdView&gt;

<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" /&gt;

<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" /&gt;
</LinearLayout&gt;   
</RelativeLayout&gt;
```

I wonder if the problem isn't in my xml file : I have a lot of difficulties to maker a clear interface with the linearlayout required by admob.


Here is the accepted answer: You aren't actually setting the listeners. You have that code in a method:

```public void onCreate1(Bundle savedInstanceState) {
```

that is never called. Move that code to the actual ```onCreate()``` method and it should work fine.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:10/23/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><android><audio><onclicklistener>', 'Title': "Phone won't play the on-click sound", 'ViewCount': 75, 'id': 19545429, 'user_AboutMe': '', 'user_AccountId': 3147467.0, 'user_DisplayName': 'user2661663', 'user_Reputation': 277.0, 'user_Views': 31.0, 'user_id': 2661663.0}}