I started an Android OpenGL application and I have the following classes:
class A extends Activity
class B extends GlSurfaceView implements Renderer
<
An alternate way to solve this, is to leave your views attached to Activity A. So instead of using setContentView(B object) you use setContentView(A object) and inside your "A XML" file, is the GLsurfaceView view:
<android.opengl.GLSurfaceView android:id="@+id/glsurfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
You can then refer to your B object in the Activity A, because it was inflated when you setContentView to A, instead of B:
GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.glsurfaceview);
glSurfaceView.setRenderer(); //no longer have to pass the object
I'm honestly not sure how to get it to work exactly the way you want, but in your case I'm not sure it ultimately makes a difference. Then again, I'm still a novice too. I'd be interested to learn how to do this in an alternate fashion as I asked a similar question just today.
Okay, so the proper way of doing this is to have a constructor in the B class which takes in:
B(Context context, AttributeSet attrs)
{
super(context, attrs);
}
And in the XML layout, use this:
<com.bla.bla.B
android:id="@+id/glsurfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The thing that was missing in my code was the constructor signature.