Имам персонализиран изглед, наречен GLView, който разширява класа GLSurfaceView. Вътре в този GLView искам да осъществя достъп до другия TextView, който се съдържа в родителско линейно оформление. Когато извикам this.getParent, той връща NULL, така че погледнах и eclipse наистина казва, че mparent е null. някой знае ли защо
Клас на дейност, който извиква View
package org.kizik.WLTBO;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class WholettheballoutActivity extends Activity {
GLView view;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.score);
view = (GLView) findViewById(R.id.mySurfaceView);
// You can use a FrameLayout to hold the surface view
/*FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(view);
// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout= new RelativeLayout(this);
relativeLayout.addView(frameLayout);
relativeLayout.addView(score);
setContentView(relativeLayout);*/
}
@Override
protected void onPause() {
super.onPause();
view.onPause();
}
@Override
protected void onResume() {
super.onResume();
view.onResume();
}
}
XML файл
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/parent" >
<TextView android:id="@+id/textView2"
android:text = "Points 12345 Time:"
android:gravity="center_horizontal"
android:textSize="22sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<org.kizik.WLTBO.GLView
android:id="@+id/mySurfaceView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
Вероятно не е необходимо, но ето конструкторите в класа GLView
public GLView(Context context) {
super(context);
// Uncomment this to turn on error-checking and logging
//setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
renderer = new GLRenderer(context, view);
setRenderer(renderer);
}
public GLView(Context context, AttributeSet attrs){
super(context,attrs);
view = this.getParent();
renderer = new GLRenderer(context, view);
setRenderer(renderer);
}