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();
}
}
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:
Here’s an example of the code you would need in your source/original activity: