Android:ActionBarActivity findViewById return NULL

眉间皱痕 提交于 2019-12-01 14:39:00

You are trying to search inside Activity's layout, and your widgets are inside a Fragment's layout.

Put your logic inside your PlaceHolderFragment class:

public static class PlaceholderFragment extends Fragment implements OnClickListener {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);

        mplayer = new MediaPlayer();
        rgroup = (RadioGroup) rootView.findViewById(R.id.radioGroup1);

        play = (Button) rootView.findViewById(R.id.play);
        pause = (Button) rootView.findViewById(R.id.pause);

        play.setOnClickListener(this);
        pause.setOnClickListener(this);

        return rootView;
    }

    @Override
    public void onClick(View v) {

    } 
}

P.S. Салам алейкум =)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!