CCTextFieldTTF won't work on Android on Lua project

I went through a lot of investigation: http://cocos2d-x.org/boards/10/topics/7561?r=7861

Now I got to a part where don’t know where to go further.

It seems that due to a different way Activity is created on normal cocos2dx android projects then in Lua android projects I cannot use the text field.
I’ve tried changing my activity to set the mTextField variable, but when I try to get R.id.textField it’s null, where in normal android project [I used android tests project] it is a reference to a widget.

Any tips on how to proceed with this?

Thanks,
Krystian

Yes!
Finally got it

What I did was:

  • Create class org.cocos2dx.lib.LuaGLSurfaceView
    <pre>
    package org.cocos2dx.lib;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;

public class LuaGLSurfaceView extends Cocos2dxGLSurfaceView {

public LuaGLSurfaceView(Context context, AttributeSet set) {
super(context, set);
}

public LuaGLSurfaceView(Context context) {
super(context);
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
// exit program when key back is entered
if (keyCode == KeyEvent.KEYCODE_BACK) {
android.os.Process.killProcess(android.os.Process.myPid());
}
return super.onKeyDown(keyCode, event);
}
}

- Remove inner class `LuaGLSurfaceView` from the activity generated for your app - Modify `res/layout/game_demo.xml` : change `org.cocos2dx.lib.Cocos2dxGLSurfaceView` to `org.cocos2dx.lib.LuaGLSurfaceView` - Modify code in your activity from:
mGLView = new LuaGLSurfaceView(this);
setContentView(mGLView);

to:

        setContentView(R.layout.game_demo);
        mGLView = (LuaGLSurfaceView) findViewById(R.id.game_gl_surfaceview);
        mGLView.setTextField((EditText)findViewById(R.id.textField));

and also change declaration:

private GLSurfaceView mGLView;

to:

private Cocos2dxGLSurfaceView mGLView;

Now rebuild your project and you are ready to go :slight_smile: