title: How to change 3D objects when button was clicked on android?
body: <p>May I know how to I change the 3D object in the GLSurfaceView when the button was clicked? My application keep closing whenever I run it on my device. I have 2 classes which implements GLSurfaceView.Renderer which is LessonOneRenderer and LessonOneRenderer2. And I put this code in the button onClick</p>
  
  <pre><code>mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.glSurfaceViewID);
                  mGLSurfaceView.setRenderer(new LessonOneRenderer2());
  </code></pre>
  
  <p>but it doesnt work.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:id= "@+id/linearlayout1" &gt;
  
      &lt;Button
          android:id="@+id/buttonID"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dip"
          android:text="A Button" /&gt;
  
      &lt;com.example.test3.MyGLSurfaceView
          android:id="@+id/glSurfaceViewID"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.23" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>==============</p>
  
  <pre><code>package com.example.test3;
  
  import android.app.Activity;
  import android.app.ActivityManager;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.DialogInterface.OnClickListener;
  import android.content.pm.ConfigurationInfo;
  import android.opengl.GLSurfaceView;
  import android.os.Bundle;
  import android.util.AttributeSet;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity extends Activity implements android.view.View.OnClickListener
  {
      /** Hold a reference to our GLSurfaceView */
      private GLSurfaceView mGLSurfaceView;
      private Button btn;
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
  
  
          //mGLSurfaceView = new GLSurfaceView(this);
           //setContentView(R.layout.activity_main);
          //mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.glSurfaceViewID);
  
  
  
          // Check if the system supports OpenGL ES 2.0.
          final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
          final boolean supportsEs2 = configurationInfo.reqGlEsVersion &gt;= 0x20000;
  
          if (supportsEs2) 
          {
              // Request an OpenGL ES 2.0 compatible context.
              //mGLSurfaceView.setEGLContextClientVersion(2);
  
              // Set the renderer to our demo renderer, defined below.
              //mGLSurfaceView.setRenderer(new LessonOneRenderer());
              //mGLSurfaceView.setRenderer
              setContentView(R.layout.activity_main);
              //mGLSurfaceView.setRenderer(new LessonOneRenderer());
              //MyGLSurfaceView.mRenderer = new LessonOneRenderer();
              mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.glSurfaceViewID);
  
              mGLSurfaceView.setRenderer(new LessonOneRenderer());
  
          } 
          else 
          {
              // This is where you could create an OpenGL ES 1.x compatible
              // renderer if you wanted to support both ES 1 and ES 2.
              return;
          }
          //setContentView(R.layout.activity_main);
          //setContentView(mGLSurfaceView);
          btn = (Button)findViewById(R.id.buttonID);
          btn.setOnClickListener(this);
      }
  
      @Override
      protected void onResume() 
      {
          // The activity must call the GL surface view's onResume() on activity onResume().
          super.onResume();
          mGLSurfaceView.onResume();
      }
  
      @Override
      protected void onPause() 
      {
          // The activity must call the GL surface view's onPause() on activity onPause().
          super.onPause();
          mGLSurfaceView.onPause();
      }   
  
      public void onClick(View v)
      {
          if(v == btn)
          {
              //finish();
              mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.glSurfaceViewID);
              mGLSurfaceView.setRenderer(new LessonOneRenderer2());
          }
      }
  
  }
  </code></pre>
  
  <p>======================</p>
  
  <pre><code>package com.example.test3;
  
  import android.content.Context;
  import android.opengl.GLSurfaceView;
  import android.util.AttributeSet;
  
  
  public class MyGLSurfaceView extends GLSurfaceView{
  
      public MyGLSurfaceView(Context context) {
          super(context);
          setEGLContextClientVersion(2);
      }
  
      public MyGLSurfaceView(Context context, AttributeSet attrs){
          super(context,attrs);
          setEGLContextClientVersion(2);
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Thank you.</p>