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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:26:59+00:00 2026-06-01T20:26:59+00:00

Main Activity with button I want changed. It should import what the user put

  • 0

Main Activity with button I want changed. It should import what the user put in the EditText from the other activity:

@Override
protected void onResume() {
    super.onResume();

    class1.setText(this.getButtonText());
}

public String getButtonText()
{
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String buttonText = prefs.getString("ButtonText", "Default Button Test");
    return buttonText;
}

Activity with Edit text and a button to take the user back to the main page. I tried to use the shared preferences but am not sure how to do it?:

 Button class1;


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

        SettingButtons();
        class1.setOnClickListener(this);

 }


private void SettingButtons() {
    // TODO Auto-generated method stub
    class1 = (Button) findViewById(R.id.edittoclass1);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.edittoclass1:
        startActivity(new Intent("com.clayton.calendar.TOCLASS"));
    break;

    }
}






protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = prefs.edit();
    editor.putString("ButtonText",  // This is not working
            ((TextView)findViewById(R.id.edittoclass1)).getText().toString());
    editor.commit();
    }

}

  • 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-01T20:27:00+00:00Added an answer on June 1, 2026 at 8:27 pm

    Create a new activity which contains an EditText. When the user long clicks the button in your source activity, take them to this new activity. In the onPause of the new activity, save the text of the EditText to a value in your shared preferences. Then, in the onResume of your source activity, take the value from the shared preferences and set your buttons text value to this value.

    Here’s an example of some code you would need for the onPause of the edit button text activity:

    @Override
    protected void onPause() {
        super.onPause();
    
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        Editor editor = prefs.edit();
        editor.putString("ButtonText", ((TextView)findViewById(R.id.buttonText)).getText().toString());
        editor.commit();
    }
    

    Here’s an example of the code you would need in your source/original activity:

    @Override
    protected void onResume() {
        super.onResume();
    
        button.setText(this.getButtonText()); 
    }
    
    
    public String getButtonText()
    {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String buttonText = prefs.getString("ButtonText", "Default button text");
        return buttonText;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a new MapActivity class MapProba . From main Activity I want to
In my main activity I have a button with the text Play. I want
For tracking user activity, I am using a Windows Hook for the main application
I'm going from main activity to another activity and then when I press back
I am using Button in main Activity. When i clicked this button it will
I have a Main-Activity which displays several spinners. With a Toggle-Button in the Main-Activity
i have two sub activities apart from main activity. The sequence of calls go
I want main activity to wait while dialog box is excuted. I tried this.wait();
In my application I start a Register activity from the Main Activity with a
So I want to use a button to lead over to a new activity

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.