android JNI,如何使用findViewById

时间:2013-03-19 07:55:11

标签: android java-native-interface

在C ++中调用findViewById的代码是什么?什么是C ++中的ID类型?字符串,整数,指针? GetMethodID的签名是什么?

string ID = "sample id";
jFindViewById = (env)->GetMethodID(cls, "findViewById", "ILjava/lang/Id;)Ljava/lang/Object;");
jobject myView = (jobject) (env)->CallObjectMethod(Obj, jFindViewById, ID);

1 个答案:

答案 0 :(得分:0)

我自己刚刚找到了答案,但这并不是很明显,但经过一个小时的试错后我得到了答案。希望它对其他人有所帮助。

your jni funcion declaration... (JNIEnv* env, jobject Obj) {
   jmethodID jfindViewById = 0;
   int ID = 2; //get the ID somewhere else, it is just an integer.
   jfindViewById = (env)->GetMethodID(cls, "findViewById", "(I)Landroid/view/View;");
   jobject image_view = (jobject) (env)->CallObjectMethod(Obj, jfindViewById, ID);
}