2013-03-19 71 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); 
}