i'm programming an android game and therefore im using a class that extends surfaceview.
My Activity looks like this:
public class GameActivity extends FragmentActivity {
private Fragment fragEnd;
private GameView gameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView = new GameView(this);
setContentView(gameView);
fragEnd = (FragmentEnd) Fragment.instantiate(this, FragmentEnd.class.getName(), null);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add( WHAR COMES IN HERE??? , fragEnd);
ft.commit();
}
...
The GameView class extends the surfaceview.
My activity_game.xml layout file looks like this:
<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=".GameActivity"
android:id="@+id/myView">
</RelativeLayout>
So there is nothing special defined in my xml.
Now i want to use fragments in the game for options etc. I read some tutorials and added the components to my (Fragment)Activity. But i recieve an IllegalArgumentException: "no view found" while trying to create the fragment. i know that the problem is, that the current view (Surfaceview) cannot be found. in the tutorials, they only worked with layout xmls like writing:
setContentView(R.layout.activity_main);
And then get the component (for example the Relativelayout id "relativeLayoutView") of the activity_main to define the
ft.add( R.id.relativeLayoutView , fragEnd);
But in my case there is nothing in my activity_main because all happens ins the gameView-class.
How do i solve this to display fragments?