3

I have problems with incorporating the world map on a fragment android Since an activity is performed in this way :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final RajawaliSurfaceView surface = new RajawaliSurfaceView(this);
    surface.setFrameRate(60.0);
    surface.setRenderMode(IRajawaliSurface.RENDERMODE_CONTINUOUSLY);

    // Add mSurface to your root view
    addContentView(surface, new  ActionB

ar.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT));

    renderer = new Renderer(this);
    surface.setSurfaceRenderer(renderer);
}

But when I want to do it in a fragment gives me error line

addContentView(surface, new  ActionBar.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT));


  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final RajawaliSurfaceView surface = new RajawaliSurfaceView(getActivity());
        surface.setFrameRate(60.0);
        surface.setRenderMode(IRajawaliSurface.RENDERMODE_CONTINUOUSLY);

        // Add mSurface to your root view
        addContentView(surface, new ActionBar.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT));

        renderer = new Renderer(getActivity());
        surface.setSurfaceRenderer(renderer);
    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

4

Well i think you are misunderstanding the difference between a Fragment and Activity, this error message:

cannot find symbol method addContentView()

points that this method doesn´t exist!

This is a very basic example of how to load the Rajawali3D map into fragment Android.

enter image description here

Create the Activity, adding the Fragment transaction, the fragment is loaded into the map_fragment container, defined in act_frag_map layout:

public class Map3DFragActivity extends AppCompatActivity {

    public RajawaliSurfaceView rajawaliTexture;
    Renderer renderer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_frag_map);

        setFragment();

    }

    protected void setFragment() {
        FragmentManager fragmentManager = getSupportFragmentManager();
        Fragment mapFragment = new FragmentMap();
        FragmentTransaction ft =
                fragmentManager.beginTransaction();
        ft.add(R.id.map_fragment, mapFragment).commit();
    }

}

This is the layout containing a fragment, adding in the property android:name the name of our class fragment:

act_frag_map

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentExampleActivity" >

    <fragment
        android:id="@+id/map_fragment"
        android:name="com.test.FragmentMap"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
         />
</RelativeLayout>

This is the Fragment that creates the map!

FragmentMap

import org.rajawali3d.surface.RajawaliSurfaceView;

public class FragmentMap extends Fragment {

    public RajawaliSurfaceView rajawaliTexture;
    Renderer renderer;


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

        rajawaliTexture = (RajawaliSurfaceView) view.findViewById(R.id.rajawali_surface);
        renderer = new Renderer(getActivity());
        rajawaliTexture.setSurfaceRenderer(renderer);

        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); // make sure this line exists

    }
}

activity_frag_map

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:surfaceview="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <org.rajawali3d.surface.RajawaliSurfaceView
        android:id="@+id/rajawali_surface"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        surfaceview:frameRate="60.0"
        surfaceview:renderMode="RENDER_WHEN_DIRTY"/>

</FrameLayout>
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • Thanks But I still have problems , now is activity_frag_map , rendering Problems java.lang.NullPointerException at android.opengl.GLSurfaceView.onResume(GLSurfaceView.java:562) you have the code from this example? We appreciate it if I can I send my gmail . mf.reyessn@gmail.com Thank you – Mauricio Felipe Reyes Nuñez Mar 18 '16 at 19:52