0

I want to change the contents of an EditText on another Activity with a button.

Both activities extend from the same parent.

How can I do this?

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
user576820
  • 1,289
  • 2
  • 11
  • 13
  • 2
    @user576820: "I want to change the contents of an EditText on another activity with a button, how can I do this?" You don't, any more than you change the contents of one field on a Web page from another Web page in a Web app. However, since you declined to provide any actual details of what business logic you are trying to implement, I can't give you any suggestions on how to actually solve that business problem. – CommonsWare Feb 05 '11 at 20:14
  • 1
    Every time you put *Android* in the question title a kitten will die so please stop doing that. Thanks. – Octavian Helm Feb 05 '11 at 20:17
  • CommonsWare is correct. If you want the button to *start* an `Activity` and pass data to it, there are ways of doing that. If you want the button to save a user preference so that when they later go to your other `Activity` you can read that preference, there are ways of doing that too. Please provide more details of the problem you are actually trying to solve. – dave.c Feb 05 '11 at 20:20
  • Tried and this doesn't work: Add.this.input2.setText("568.26"); – user576820 Feb 05 '11 at 20:27
  • Tried setting a global variable with the button and then getting the other activity to read it when the back key is pressed but it's as if it never changed the variable :? – user576820 Feb 05 '11 at 20:47

1 Answers1

0

i recently started learning about java events and listeners. I believe my SO question may help you. Here is the link to my question.

Basically what you can do is set up an event for when they press the button and then have a listener and have the listener trigger the change. Take a look at my question for more detail. If you take a look at the accepted answer you will see a great example i made.

Community
  • 1
  • 1
prolink007
  • 33,872
  • 24
  • 117
  • 185
  • 1
    "Basically what you can do is set up an event for when they press the button and then have a listener and have the listener trigger the change." -- well, no. Activities cannot and should not have any way to directly communicate with other activities, otherwise you will wind up with garbage collection problems and memory leaks. Your listener pattern, while verbose, is unsuitable for the OP's situation. – CommonsWare Feb 05 '11 at 20:24
  • So if they shouldn't be able to communicate what I am asking is then not really possible? – user576820 Feb 05 '11 at 20:45