Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:23:59+00:00 2026-05-27T12:23:59+00:00

IS there any way that I can update a TextView when user click on

  • 0

IS there any way that I can update a TextView when user click on scene in AndEngine. I’m trying to update my text view,but it’s throwing me an exception. Here is what I’m doing :

Adding the textview :

@Override
protected void onSetContentView() {
    final FrameLayout frameLayout = new FrameLayout(this);
    final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);

    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine);
    final FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);

    hm = getIconNames();

    text = new TextView(this);
    text.setPadding(20, 10, 10, 10);
    text.setText(hm.get(title));
    text.setTextColor(Color.parseColor("#000000"));
    frameLayout.addView(text);

    //Create any other views you want here, and add them to the frameLayout.

    this.setContentView(frameLayout, frameLayoutLayoutParams);
}

And I’m trying to do this :

@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
    if(this.mPhysicsWorld != null) {
        if(pSceneTouchEvent.isActionDown()) {
            title++;
            text.setText(hm.get(title));
            this.addFace(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
            return true;
        }
    }
    return false;
}

and it’s throwing me this error :

12-15 12:32:15.584: E/AndroidRuntime(1468): FATAL EXCEPTION: UpdateThread
12-15 12:32:15.584: E/AndroidRuntime(1468): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.view.ViewRoot.checkThread(ViewRoot.java:3165)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:690)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:716)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2624)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.view.View.invalidate(View.java:5341)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.widget.TextView.checkForRelayout(TextView.java:5778)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.widget.TextView.setText(TextView.java:2817)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.widget.TextView.setText(TextView.java:2685)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at android.widget.TextView.setText(TextView.java:2660)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.hardartcore.stefan.kunchev.Game.onSceneTouchEvent(Game.java:245)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.entity.scene.Scene.onSceneTouchEvent(Scene.java:353)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.engine.Engine.onTouchScene(Engine.java:409)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.engine.Engine.onTouchEvent(Engine.java:395)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.input.touch.controller.BaseTouchController$TouchEventRunnablePoolItem.run(BaseTouchController.java:126)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.util.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:47)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.util.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:1)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.util.pool.PoolUpdateHandler.onUpdate(PoolUpdateHandler.java:85)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.input.touch.controller.BaseTouchController.onUpdate(BaseTouchController.java:68)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.engine.Engine.onUpdate(Engine.java:481)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.engine.Engine.onTickUpdate(Engine.java:459)
12-15 12:32:15.584: E/AndroidRuntime(1468):     at org.anddev.andengine.engine.Engine$UpdateThread.run(Engine.java:685)

Any idea how to fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:24:00+00:00Added an answer on May 27, 2026 at 12:24 pm

    You can’t update a native view from the update thread, you must do so in the UI thread.
    You can do:

    @Override   
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {   
        if(this.mPhysicsWorld != null) {   
            if(pSceneTouchEvent.isActionDown()) {   
                title++;   
                text.post(new Runnable() {
                    @Override
                    public void run() {
                        text.setText(hm.get(title));           
                    }
                }; 
                this.addFace(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());   
                return true;   
            }   
        }   
        return false;   
    }   
    

    This will work, but you should consider using an AndEngine entity to display information to the user, maybe use ChangeableText class which is pretty much like a text view, or use a HUD which lets you add several entites at once, to be shown over the scene.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can programmatically create (and I guess access) hidden
Is there any way that I can change how a Literal of a code
Is there any way that I can find the container pointed to by an
Is there any way that I can create a new delegate type based on
Is there any way that I can use C# to load and then render
Is there any way that I can pass arguments in selector? example: I have
Is there any way that I can list the pages which are currently stored
Is there any way that I can call a JavaScript function via css? For
Is there any way that I can detect browser type on routing and use
I wish to know is there any way that I can create the threads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.