I have a class that consists of an edittext box to hold a string "strResponse" I want to access this string in another class. Basically a user types in whatever, and the other class takes that string, and sends it in a text message.
That code works fine if I hard code it in. But I want a user to define what the message should say from the other class.
I was thinking global variable, but have had no luck so far.
-
How is your class structure looks like? For UI type interaction, typically you should use event handling mechanism where your class which does the message sending will be notified when the "strResponse" is changed in the edittext box.DJ.– DJ.2011-02-10 20:45:46 +00:00Commented Feb 10, 2011 at 20:45
-
Hi DJ, how does this mechanism work?GrumP– GrumP2011-02-11 22:48:08 +00:00Commented Feb 11, 2011 at 22:48
2 Answers
what do you mean by hardcode it? could you post your code here?
normally, a decent oop design isn't class 1 "takes" values from class 2, if class 2 is the one which is taking inputs from the user.
The design should be something, class 2 takes input and once input is done it sends/flag/notify class 1 for updated value.
sends/flag/notify could be done by different ways. depends on the design.
7 Comments
I think you need to access the string value of dialog box class to the main Activity class. (Just a for example)
You need interface to do this. i Think link will help
http://developmentality.wordpress.com/2009/10/31/android-dialog-box-tutorial/
In the above link string value in the dialog class is accessed in main activity call using the interface.
Hope this will solve your issue.