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 7013437
In Process

The Archive Base Latest Questions

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

My problem is communication between custom GameView (extends SurfaceView) and TextView: I want to

  • 0

My problem is communication between custom GameView (extends SurfaceView) and TextView: I want to set TextView’s text from inside of the GameView.
In main activity i’m using this layout file, it should explain structure of my app:

<?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"
>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:background="#00ff00"
    >
    <TextView
        android:id="@+id/scoreTV"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="score: 0" 
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="back"
        android:layout_alignParentRight="true" />                   
</RelativeLayout>
<org.gk.grApp.GameView
    android:id="@+id/gameplayScreen"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    />
</LinearLayout>

I can’t change TextView’s text in my GameView object, because it’s impossible to touch UI thread from another.
Handler doesn’t work too, because i can’t give a handler’s reference to GameView’s constructor, that is performed after loading this xml file (a read about default constructor for xml files eg here How can I use GLSurfaceView in a LinearLayout together with other Views, such as TextView or Button?).
Do you have any idea what I should do now? Maybe my deduction is wrong, so please, tell me about this.

EDIT: I changed my xml file, instead of GameView I have now:

<LinearLayout
    android:id="@+id/gameplayScreen"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    >
    </LinearLayout>

Also I added an argument (third) into constructor’s signature:

public GameView(Context context, AttributeSet as, Handler h) { ... } 

and changed my onCreate in GameplayActivity:

protected void onCreate(Bundle savedInstanceState) {        
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gameplay);

    LinearLayout ll = (LinearLayout)findViewById(R.id.gameplayScreen);
    GV = new GameView(this, null, scoreHandler);
    ll.addView(GV);         
}

It works, now I can set TextView’s text but after clicking on the back button another exception is thrown:
“Performing pause of activity that is not resumed: {org.gk.grApp/org.gk.grApp.MainMenuActivity}”. I just started searching information about 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-27T22:23:15+00:00Added an answer on May 27, 2026 at 10:23 pm

    First make a reference to the TextView on the activity level:

    TextView txv;

    In onCreate assign this reference:

    txv = (TextView) findViewById(R.id.MyTextView);

    Then make a method in your Activity after onCreate like this:

    public void setTextView(final String txt){
        MyActivity.this.runOnUiThread(new Runnable() {     
            public void run() {         
                txv.setText(txt);     
            } 
         });
    }
    

    Then you make a call from your custom view:

    ((MyActivity) getContext()).setTextView(str);

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

Sidebar

Related Questions

I am having a problem with a Serial Port communication between Arduino Nano and
here's my problem. I am using WCF for communication between two services. I am
I do have a communication problem here between my Java servlet and an Ajax
Problem: I have a set of data that keeps track of history of communication
I got some problems with EOF and stdio in a communication pipeline between a
I'm kind of curious how I should approach a problem with iPhones and communication
Problem: I have an address field from an Access database which has been converted
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem is described and demonstrated on the following links: Paul Stovell WPF: Blurry Text
I have a question about how to structure communication between a (new) Firefox extension

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.