所以我创建了两个应用程序。一个是在我点击按钮时发出声音而另一个是导航抽屉活动。我想做的就是把这个带声音的按钮放到我创建的一个片段上,但它对我不起作用。我只是在youtube上观看教程的初学者
我想把这个
public class MainActivity extends AppCompatActivity {
SoundPool mySound;
int anotheroneId;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
anotheroneId = mySound.load(this, R.raw.anotherone, 1);
进入这个
public class FragmentThree extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_three,container,false);
}
答案 0 :(得分:0)
你必须像这样重写onActivityCreated方法
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mySound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
anotheroneId = mySound.load(getActivity().getApplicationContext(), R.raw.anotherone, 1);
}