Q:

Cant put sound button into fragment

So I have two apps created. One is making sound when I click the button and the second one has a navigation drawer activity. All I want to do is put this button with sound to the one of the fragments I have created but it doesnt work for me. Im total beginner who just watching tutorials on youtube
I want to put this 
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);

Into this
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);
}

A:

You have to override the method onActivityCreated like this 
@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);
}

