2013-03-19 77 views
1

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

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

回答

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); 
}