Search code examples
rajawali

RajawaliFragment not working?


I'd like to create an App that has 3D output among other GUI elements, especially the task bar. After I got the example to work using the RajawaliActivity (the Tutorial 1), I failed to do the same thing using a RajawaliFragment.

Unfortunately I couldn't find an example using the RajawaliFragment and the stable version 0.9, is there something more to it?

My RajawaliFragment:

public class MyFragment extends RajawaliFragment {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MyRenderer renderer = new MyRenderer(getActivity());
        renderer.setSurfaceView(mSurfaceView);

        super.setRenderer(renderer);
    }
}

The Renderer is (except for the name) a copy of the example code and did work fine with the RajawaliActivity. Also, the fragment does get attached, but none of the renderer methods get called (except for the constructor of course).


Solution

  • The thing I missed was the onCreateView method. I thought it was all just about the loading screen I didn't need, so I omitted it, but what I actually needed to do was this:

    public class MyFragment extends RajawaliFragment {
        public void onCreate(Bundle savedInstanceState) {
            // this part was fine
        }
    
        public View onCreateView(LayoutInflater i, ViewGroup c, Bundle b) {
            return mSurfaceView;
        }
    }