I donβt think that you need to use handlers to solve this problem, but you may need to set up a way to organize your classes.
Here is an example of an organizational structure that can solve your problem:
Action class
public class MainActivity extends Activity { private int modelNumber = 0; private ArrayList<Model> models = new ArrayList<Model>(); private YourRendererClass renderer; @Override public void onCreate(Bundle savedInstanceState) { ...
Renderer class
public class YourRendererClass implements Renderer { private Model currentModel; @Override public void onDrawFrame(GL10 gl) {
Model class
public class Model { // Holds model information private int size; private int x; private int y; // etc... public model(int x, int y, int size etc...){ this.x=x; this.y=y; this.size=size; // etc.... } public void draw(GL10 gl) { // ** Draw model based on model information fields above ** } }
The above code is untested, since I do not have access to your drawing code, but the structure should work if it is executed correctly. I tried to make it clear where you have to insert your own code for it to work. In particular, I was not sure what defines each of your different models, so you need to include enough local variables in the Model class to define them.
Hope my answer helps, let me know if you have any questions.
Tim
source share