Hello guys
I have ported my iphone app to android using ndk and cocos2dx.
This has worked like a charm and I think cocos2dx is very cool!
Now I would like to add some Java views to my main opengl view in the Java environment.
And this is not really working for me. I think I need basic knowledge about have views, activitis, Intent
etc works in the Java environment.
To be specific I need to add a TextView
(java) to my opengl view at runtime.
I have tried the following but it crashes when I call the function public void testSetText()
.
public class myTest extends Cocos2dxActivity{
private static final String TAG = "MY_TEST";
private FrameLayout mainFrame;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Log.e(TAG, "onCreate");
String packageName = getApplication().getPackageName();
super.setPackageName(packageName);
mainFrame = new FrameLayout(this);
mGLView = new Cocos2dxGLSurfaceView(this);
mainFrame.addView(mGLView);
RelativeLayout base = new RelativeLayout(this);
base.addView(mainFrame);
setContentView(base);
}
private GLSurfaceView mGLView;
static {
System.loadLibrary("cocos2d");
System.loadLibrary("cocosdenshion");
System.loadLibrary("game");
}
@Override
protected void onPause() {
super.onPause();
Log.i("TAG"," onPause");
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
Log.i("TAG"," onResume");
mGLView.onResume();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.e(TAG, "onStart");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.e(TAG, "onStop");
}
public void testSetText(){
Log.e(TAG, "testSetText");
TextView textView = new TextView(this);
textView.setText("Hello, Android");
LinearLayout testLayout = new LinearLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
testLayout.addView(textView ,lp);
mainFrame.addView(testLayout);
}
}
And if I instead try to run another activity- or call setContentView(R.layout.test_screen)
in the function public void testSetText()
my game also crashes.
Could anyone give me some good advise here?
Thank you so much.