当用户选中一个框时,我想要一个声音点击。我使用 Ubuntu Natty、Eclipse Indigo,我的代码适用于 Android 2.2。编译正常,但没有声音。我在谷歌中寻找了一个简单的编码,但只有我在这个问题上找到了复杂的例子,想知道。这是我的代码,有什么问题?
package com.stufflist;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
public class ListStuff extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.liststuff);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.liststuff, menu);
return true;
}
public void onCheckboxClicked(View view) {
// Is the view now checked?
view.setSoundEffectsEnabled(true);
boolean checked = ((CheckBox) view).isChecked();
// Check which checkbox was clicked
switch(view.getId()) {
case R.id.CheckBox07:
if (checked)
view.playSoundEffect(0);
Log.v((String) view.getTag(),"yeah");
break;
case R.id.CheckBox06:
if (checked)
view.playSoundEffect(1);
Log.v((String) view.getTag(),"yeah2");
break;
// TODO: Veggie sandwich
}
}
}