0

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.

2
  • 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. Commented Feb 10, 2011 at 20:45
  • Hi DJ, how does this mechanism work? Commented Feb 11, 2011 at 22:48

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I have this in a particular class - String strResponse = responseText.getText().toString(); and this: String message="Hey - got your message!"; SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(from, null, message, null, null); In another class which sends a text message with the "message" string. I want to send the string stored in the edit text box.
sounds like you have 2 independent classes and these 2 independent classes have to be associated with one class. MainClass should contain the "particular" class which is taking the input. and once input is done, mainclass should get string from that class particularClass.getMessage() and send it to SMSManager.sendMessage();
alternately, your particular class should contain the SmsManager object, and once it is done with the input, it should call a method from SmsManager to send the sms.
Hmmmm.... thanks alee but I'm not quite sure what you mean. The way I have put together the code is pretty odd at the minute. Perhaps I should try keep it a bit more structured instead of having new classes everywhere! It would make it alot easier I think :-\
thats the reason i asked you to put your code here. I am not asking for "detail" code. Just put in details the name of the classes and the method names.
|
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.