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

  • Home
  • SEARCH
  • 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 8552545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:26:47+00:00 2026-06-11T14:26:47+00:00

I have two classes. The first is an Activity containing the usual layout. The

  • 0

I have two classes. The first is an Activity containing the usual layout. The second is a thread-based SurfaceView class. My question is exactly the same as this topic, but with Thread instead of AsyncTask:

Android/Java: Change view from another class?

When the thread causes certain events, I want to be able to update other Views in the Activity, but I cannot seem to find a method for correctly accessing those Views from within the SurfaceView.

public class MyActivity extends Activity{

    Button myButton = (Button)findViewById(R.id.my_button);
    ...
}

public class MySurfaceView extends SurfaceView implements Runnable{

    // Need code here that can access myButton to call myButton.setText("Some Text")
}

Most suggestions say something like this:

((Button)findViewById(R.id.my_button)).setText("My Text");

where the my_button is originally set up in the Activity’s onCreate(). However, this always results in a null pointer when called from within the SurfaceView. Further reasoning would tell me that I’d want to access the application context to find the View that way, but that seems to leave the door open for the dreaded context memory leak.

This seems like something that should be fairly common in Android programs, but I cannot seem to find a proper way of doing 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-06-11T14:26:48+00:00Added an answer on June 11, 2026 at 2:26 pm

    Have you tried to implement a listener from SurfaceView that broadcasts event and setListener on the activity. Check here on how to implement http://tseng-blog.nge-web.net/blog/2009/02/17/how-implement-your-own-listener-android-java/

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

Sidebar

Related Questions

I have two classes. First class has TabPage control. I want to change layout
my code is like this: i have two classes first class: public class Box<E>
I have two (unrelated) classes. The first one is Point: typedef std::complex<double> complex_number; class
Let's say I have two classes. Each class has one parameter. Parameter of first
I have two classes, the first called Radish and the second called RadishCont. All
I have two classes [applicable to this question]. The first, XYAxes2 , extends FrameworkElement
I have two classes, first: public class A { public delegate void Function(); public
In my project I have two activities or classes. In first activity I have
Suppose that I have two classes, first a class without any properties, fields or
Actually I have two java classes of which one is an activity class. Now

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.