我正在做一个项目,我需要创建一些Button
s,单击它们会播放一些音调。这是我使用的代码
package com.entrainment.www;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button mButtonOne;
Button mButtonTwo;
MediaPlayer mp;
MediaPlayer mp1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mp=MediaPlayer.create(this, R.raw.tone_1);
mp1=MediaPlayer.create(this, R.raw.tone_2);
mButtonOne = (Button)findViewById(R.id.button1);
mButtonTwo = (Button)findViewById(R.id.button2);
mButtonOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
mp.start();
}
});
mButtonTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
mp1.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我已经让 AVD 运行,一切都很好,但是当我点击按钮时,什么也没有发生。