我正在使用Android,並且正在開發OpenGL ES。我有一個XML佈局如下(我已經花了一些東西出來,只顯示therelative內容:GlSurfaceView內的佈局訪問按鈕
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/myText"/>
<MyGLSurfaceView
android:id="@+id/mySurface"/>
然後在我的GlSurfaceView我試圖訪問按鈕是相同的佈局然而這是我有一個問題
我曾嘗試以下:
View v = (View) getParent();
myTextViewString = (TextView) v.findViewById(R.id.myText);
這
myTextViewString = (TextView) findViewById(R.id.myText);
這
myTextViewString = (TextView) ((RelativeLayout) getParent()).findViewById(R.id.myText);
我似乎無法弄清楚如何訪問此按鈕GLSurfaceView之外,但在我GLSurfaceView.java內相同的活動。
我知道它與無法獲得父母(我假設,因爲它不擴展活動)有關。我環顧四周,無法找到實現這一目標的途徑。
任何幫助,非常感謝。謝謝,
爲什麼不將'Context'或只是按鈕從活動傳遞到'GLSurfaceView'?然後,您不必在視圖中跳過箍環即可訪問它。 –
你能提交一個關於如何完成傳遞和使用我獲得ID的答案。所以我可以標記它是正確的。這是一個有趣的想法,我沒有想到 – L1ghtk3ira