Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to change button text loaded from edittext while in onPause() method

for example
JavaScript
@Override
protected void onPause() {
	button.	setText(text.getText().toString());	
	super.onPause();}

so when I press back button and relaunch the app it does not changed the button text
mean the changed does not saved
Posted
Updated 13-Jul-15 4:28am
v4

1 solution

You have to save your settings yourself and then restore them onResume. See http://developer.android.com/training/basics/activity-lifecycle/pausing.html[^].
 
Share this answer
 
Comments
wajib rehman 13-Jul-15 23:34pm    
ok sir please help me in this case i want to change button text loaded from edittext so
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub

super.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
please please write the code in this onResum mehtod,onPause method and onsavedInstance
for a button text change loaded from the edittext
such as the button and edittext is button.setText(text.getText().toString());
kindly please help me in this,,i am trying from a while but cannot find just like this solution.there is no way for this on google etc please write the code for this method i will be very thankful to you ..
wajib rehman 14-Jul-15 0:36am    
the code as below


package com.example.simple;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.util.Log;

public class MainActivity extends Activity {


private EditText text;
private static Button button;





@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text=(EditText)findViewById(R.id.text);
button=(Button)findViewById(R.id.button1);
radio=(RadioButton)findViewById(R.id.radioButton1);
button.setOnClickListener(new View.OnClickListener() {

@SuppressLint("NewApi") @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

button.setText(text.getText().toString());


}
});

}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
Log.d("Text's text:" + text.getText().toString()
+ "Button:" + button.getText().toString(), null,null);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d("Text's text:" + text.getText().toString()
+ "Button:" + button.getText().toString(), null,null);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
// button.setText(text.getText().toString());
super.onResume();
Log.d("Text's text:" + text.getText().toString()
+ "Button:" + button.getText().toString(), null, null);
}
;





@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
Log.d("Text's text:" + text.getText().toString()
+ "Button:" + button.getText().toString(), null, null);
}
private void onDestroye() {
// TODO Auto-generated method stub
Log.d("Text's text:" + text.getText().toString()
+ "Button:" + button.getText().toString(), null, null);

}

}

so in this when i press the button text loaded from the edittext but when pres back button and then reopone the app the changed doesnot effect please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900