C ++ calls java:
C ++ calls java. Colleagues refreshed the android Edit View Control
Step 1:
Step 2: Create a layout File
Step 3:
Public static EditText myView;
Step 4: Add a text input box
LayoutInflater inflater = (LayoutInflater) getSystemService (Context. LAYOUT_INFLATER_SERVICE );
MyView = (EditText) LayoutInflater. from (this). inflate (R. layout. myedit, framelayout, false );
MyView. addTextChangedListener (watcher );
MyView. setMovementMethod (ScrollingMovementMethod. getInstance ());
Framelayout. addView (myView );
Step 5: Add a listener
TextWatcher watcher = new TextWatcher ()
{
@ Override
Public void afterTextChanged (Editable s)
{
// TODO Auto-generated method stub
Log. d (TAG, 111111 );
}
@ Override
Public void beforeTextChanged (CharSequence s, int start, int count, int after)
{
// TODO Auto-generated method stub
Log. d (TAG, 22222 );
}
@ Override
Public void onTextChanged (CharSequence s, int start, int before, int count)
{
Log. d (TAG, 33 = [TextWatcher] [onTextChanged] + s );
}
};
Step 6:
Public static void hideAdView (String [] str)
{
MHandler. obtainMessage (100, str). sendToTarget ();
}
Private static HandlermHandler = new Handler ()
{
Public void handleMessage (Message msg)
{
Switch (msg. what)
{
Case 100: // UPDATE_UI:
{
String [] arrStrings = (String []) msg. obj;
If (arrStrings [0]. equals (I'm a tititile ))
{
TestJni. this. myView. setText (C ++ Change Java EditView string Test !);
}
}
Break;
Default:
Break;
}
}
};
Supplement:
// MyView. setBackgroundColor (Color. TRANSPARENT); // the background Color is TRANSPARENT.
// Framelayout. removeView (myView); // remove the control
C ++ code
# If (CC_TARGET_PLATFORM = CC_PLATFORM_ANDROID)
# Include platform/android/jni/JniHelper. h
Void HelloWorld: goJava ()
{
JniMethodInfo jmi;
If (JniHelper: getStaticMethodInfo (jmi, org/cocos2dx/TestJni, hideAdView, ([Ljava/lang/String;) V ))
{
Jclass str_cls = jmi. env-> FindClass (java/lang/String );
Jstring str1 = jmi. env-> NewStringUTF (I'm a titile );
Jstring str2 = jmi. env-> NewStringUTF (Are yor exit game ?);
JobjectArray arrs = jmi. env-> NewObjectArray (2, str_cls, 0 );
Jmi. env-> SetObjectArrayElement (arrs, 0, str1 );
Jmi. env-> SetObjectArrayElement (arrs, 1, str2 );
Jmi. env-> CallStaticVoidMethod (jmi. classID, jmi. methodID, arrs );
}
}
# Endif
Then call
# If (CC_TARGET_PLATFORM = CC_PLATFORM_ANDROID)
GoJava ();
# Endif
Finally, compile c ++ and android