Log in or register to post comments

How to operate above the GLsurfaceView

November 4, 2010 - 6:32am #4

Hi
I have read the question that CliffWoo has asked.He wants to make a videoView on GLSurfaceView.And I need to make some Button and textView on above the VideoView,too. So I used the solution that answered for CliffWoo.
But when I want to do something else, I meet more question.
I want to change the text in textView above the GLsurfaceView, when detect the aim image. so I write like this:

    
//in the QCARSampleActivity.java                       
overlayView = View.inflate(QCARSampleActivity.this, R.layout.main, null);
                            addContentView(overlayView, new LayoutParams(
                                                        LayoutParams.FILL_PARENT,
                                                        LayoutParams.FILL_PARENT));
mButton = (Button) overlayView.findViewById(R.id.Button01);
overlayView.setVisibility(View.VISIBLE);
//here mButton is a public member

and in the ImageTargets.java, I do like these below in ImageTargetsRenderer.java

//in ImageTargetsRenderer.java
    private ImageTargets preTargets;
    public void onDrawFrame(GL10 gl){
        if (!mIsActive)
            return;

        // Call our native function to render content
            Log.d("ImageTargets","detected");
            mButton.setText("lol! I change the text in the button!!!");
        }
    }
    public ImageTargetsRenderer(ImageTargets imageTarget){
    	super();
    	preTargets = imageTarget;	
    }

in the ImageTargets.java , I have already changed the Methods of Construction

 
protected QCARSampleRenderer createRenderer()
    {
        return new ImageTargetsRenderer(this);
    }

But this time when I detected the aim image ,the programe closed , and the file named GLSurfaceView.class wil be open in Eclipse.
And there is no error log in DDMS.
I need your help to solve the Problem. many thanks~!:)

Re: How to operate above the GLsurfaceView

November 4, 2010 - 10:42am #3

Oh,sorry. When I run the program in the N1, not the the Debug mode in Eclipse,I get the Error information.But still,I don't know how to solve it. I will paste it below.Need your help, thanks

11-05 01:31:46.982: WARN/dalvikvm(8511): threadid=9: thread exiting with uncaught exception (group=0x4001d7f0)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511): FATAL EXCEPTION: GLThread 10
11-05 01:31:46.992: ERROR/AndroidRuntime(8511): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.view.View.requestLayout(View.java:8125)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.view.View.requestLayout(View.java:8125)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.view.View.requestLayout(View.java:8125)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:254)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.view.View.requestLayout(View.java:8125)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.widget.TextView.checkForRelayout(TextView.java:5378)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.widget.TextView.setText(TextView.java:2688)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.widget.TextView.setText(TextView.java:2556)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.widget.TextView.setText(TextView.java:2531)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at com.qualcomm.QCARSamples.Shared.QCARSampleActivity.playVideo(QCARSampleActivity.java:608)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at org.footoo.magic.MagicPaperRenderer.onDrawFrame(MagicPaperRenderer.java:35)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
11-05 01:31:46.992: ERROR/AndroidRuntime(8511):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

Re: How to operate above the GLsurfaceView

November 4, 2010 - 11:21am #2

The error message explains it:

CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

When you make a callback from native to Java, you are in a different thread than the Android UI. You will need to create a Handler in your UI thread to make the changes to the UI. Please see the following thread for some code snippets:

http://ar.qualcomm.at/node/2000032

- Kim

Re: How to operate above the GLsurfaceView

November 4, 2010 - 9:39pm #1

thanks for your solution ! I have solved it in your way ! many thanks!

Log in or register to post comments