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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:16:29+00:00 2026-06-13T05:16:29+00:00

I stuck at this issue many times and I passed the problem in different

  • 0

I stuck at this issue many times and I passed the problem in different ways and I’m not sure that I made it in the right way.
I simplified the problem in a the following example. I know that I can pass only the data to the class but I do want to pass the editText cause I have this problem with more difficult UI controls.

mainactivity.java

public class mainactivity extends Activity {

    public EditText clickEditText;
    int count =0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        newTxt();
    }

    public void newTxt() {
        txt = new MyText(context);
        txt.updateTextEdit("Main Activity");
    }
}

myText.java

public class MyText
{
    private Context _context;

    // constructor
    public MyText(Context context) 
    {
        _context = context;
    }

    public void updateTextEdit(String str)
    {
        private EditText strEditText;
        strEditText= (EditText)findViewById(_context.R.id.editTextClick); // ????
        strEditText.setText(str + " and myTxt");
    }
} 

if you could explain me how to fix the updateTextEdit function. i passed the context of the main activity. How can I change the editText? Thank you very much!!!

  • 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-13T05:16:31+00:00Added an answer on June 13, 2026 at 5:16 am

    If you really want to do this this way, you need to save a reference to Activity, not Context. Like this:

    public class MyText
    {
        private Activity _activity;
    
        // constructor
        public MyText(Activity activity) 
        {
            _activity= activity;
        }
    
        public void updateTextEdit(String str)
        {
            private EditText strEditText;
            strEditText= (EditText)activity.findViewById(R.id.editTextClick);
            strEditText.setText(str + " and myTxt");
        }
    }
    

    and in newTxt() you will need to change:

    txt = new MyText(context);
    

    to:

    txt = new MyText(this);
    

    But wouldn’t it be easier to just put this method inside your activity? Why do you want it in another class? If it really needs to be in another class, you could make that class an inner class of your activity and you would still have access to the activity’s methods and member variables.

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

Sidebar

Related Questions

I am stuck on this issue and cannot seem to find a way around
After reading similar questions with many variants, I'm still stuck on this issue. Here's
I have run into this issue too many times and need this to be
I'm new to iOS development and I'm stuck on this one issue...one of many
I'm having an issue where I'm preaty not sure how to resolve this and
I am stuck with this issue for a long time. I searched for this
I've been stuck on this issue for several days - any help is much
so i have been stuck with this issue for 3 weeks now and i
I am stuck here and i spend last 2 days resolving this issue but
Im stuck with this little project in C# but basically my problem is this:

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.