BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-12-2007, 07:34 AM   #1
kazack
New Member
 
Join Date: Dec 2007
Model: 8320
PIN: N/A
Carrier: tmobile
Posts: 11
Default Retrieve data from one class into another?

Please Login to Remove!

Hi there,

I have a screen class that creates a screen with my editfield, and a button.
I have another class with a listener for the button.

My problem is how do I get the user input in the editfield from one class into the fieldlistener class?

Please note that I do know how to program in php, c++ and Visual basic. I have never programmed in any form of JAVA. The code that I am submitting is code that I pieced together and modified thus far to give me the look that I currently need and that actually works.

Here is my code below:

PHP Code:
class DataScreen extends MainScreen
{
    
int USERDATA;
        public 
SalutationScreen()
    {
        
super();
        
LabelField applicationTitle 
            new 
LabelField("Get User Data");
        
setTitle(applicationTitle);
       
// RichTextField helloWorldTextField = new RichTextField("Get User Data");
       // add(helloWorldTextField);

    
EditField DATA = new EditField("DATA: """4EditField.FILTER_NUMERIC);
    
add(DATA);
    
    
ButtonField RunCode_Button = new ButtonField("Run Code");
    
FieldListener sendListener = new FieldListener();
    
RunCode_Button.setChangeListener(sendListener);
    
add(RunCode_Button);
   
   }

static class 
FieldListener implements 
    
FieldChangeListener {
        public 
void fieldChanged(Field field,
            
int context) {
              
/*HOW DO I GET the DATA from the EDITFIELD called DATA above so that way I can manipulate it?  Thanks All  */
                
    
}


Last edited by Mark Rejhon; 12-16-2007 at 03:07 PM.. Reason: Please add [code] or [php] wrappers around your code for formatting.
Offline  
Old 12-12-2007, 12:16 PM   #2
bemshaswing
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Default

declare EditField DATA globally and access the content whenever you want by calling DATA.getText()
Offline  
Old 12-12-2007, 06:24 PM   #3
kazack
New Member
 
Join Date: Dec 2007
Model: 8320
PIN: N/A
Carrier: tmobile
Posts: 11
Default Tried to Declare EditField Globally

I moved the editfiled line to the beginning of the Class SalutatonScreen.

Does this make this global for the class and all sub classes?

I then tried this and am not sure if this is right or not.

I declared int TheData. Then did TheData = DATA.getText;

And I get the following errors:

Cannot Resolve Ssymbol
symbol: variable getText
location: class net.rim.device.api.ui.component.EditField
TheData = DATA.getText;

Thanks,
Shawn
Offline  
Old 12-12-2007, 11:14 PM   #4
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Hi Shawn. You know, around here, we use parenthesis to indicate things like method calls. jk

In any event, is there a particular reason why you don't want your FieldChangeListener to be implemented by your DataScreen? I whipped up an example of that here if you want to check it out.

If you want to use a separate class as your listener that can certainly be done, but you'll need to watch your implementation so the code doesn't turn into a big tangled mess.
Offline  
Old 12-13-2007, 12:47 AM   #5
dangihitesh
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: CLDC
Posts: 29
Default

Hi,
The possible workaround could be pass your EditField object to the listener class. Pass your EditField object when u create a listener object...and add one parameterized constructur to your listener class and access this EditField Object in your listener class.

Thanks
Hitesh
__________________
Regards,
Hitesh
Offline  
Old 12-13-2007, 04:08 AM   #6
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

To make your code more readable for others you should follow the sun java code conventions

The FieldChangeListener gets the changed field as a parameter in its fieldChanged method.
You can cast it to EditField and use getText() and setText() to get or set its contents.
__________________
java developer, Devinto, hamburg/germany

Last edited by simon.hain; 12-13-2007 at 04:12 AM..
Offline  
Old 12-13-2007, 06:51 AM   #7
kazack
New Member
 
Join Date: Dec 2007
Model: 8320
PIN: N/A
Carrier: tmobile
Posts: 11
Default Thank You

Hi there,

I will be trying a few of these things and I have a book on order for J2ME. I wanted to whip something up which is why I figure I would just try to hack my away code examples etc and then if I needed help in the mean time use the forums.

So I greatly appreciate the help that all has given me.

Thanks,
Shawn

P.S. Sorry about improper code posting.
Offline  
Old 12-13-2007, 02:32 PM   #8
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

Lots of good tips.

However, whatever you do, please be careful about thread safety when multiple classes access the same objects. You don't want different threads modifying the same object. (Especially when UI and non-UI threads modify the same objects, such as a String variable, if you regularly copy the textfield into a string variable, while at the same time you also modify the string variable in the non-UI thread)

Excercise thread safe programming. I've been bitten by bugs that was fixed by declaring a variable as "synchronize", or using other thread safety techniques. Use this in non-performance critical situations (String variables that only get changed less often than a few time a second are okay.)

I have seen situations on the BlackBerry threads where it is possible for one thread to change a variable/object (even a mere boolean variable), and the value not be read correctly in the other thread for some time beyond that. They don't even need to access the variable simultaneously for this to happen; just one after the other very closely. It's a matter of milliseconds or microseconds, but is a source of a lot of "Unhandled Exception" and lockups/freezes in some of the more poorly programmed BlackBerry applications. Be familiar with thread safety, please - study that chapter very carefully!
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source

Last edited by Mark Rejhon; 12-13-2007 at 02:34 PM..
Offline  
Old 12-14-2007, 03:56 PM   #9
kazack
New Member
 
Join Date: Dec 2007
Model: 8320
PIN: N/A
Carrier: tmobile
Posts: 11
Default Wow This is awesome

Well I got an application now written and I want to start morphing the heck out of it to make is a so called USEFUL Application.

I am not at the moment to concerned about looks of if as much as the functionality of it........ Once functionality is there then I will work on the looks of it.

It took me a bit but I figured out how to typecast a string to an integer. That was very interesting, and completely different to what I am use to in other languages. But it now works. Here is an issue with current app that I have and wasn't sure without a book to overcome the issue.

The user enters a number.
they hit submit button.

It dialogs the calculation results you hit the ok button from the dialog but it displays the menu at the bottom. You have to hit the back button to get rid of it. What do I need to do so that when the user hits the submit button that the only thing on the screen that pops up is the dialog box and that is it?

Also what is the api call if you want to call it that to pull up a calendar to a specific date?

Example: User enters a number, it generates a date at random and then it opens up the calendar to that date.

Thanks,
Shawn
Offline  
Old 12-17-2007, 01:26 AM   #10
jenselense
Thumbs Must Hurt
 
Join Date: Nov 2007
Location: atm: Kunming norm: Berlin
Model: 8700v
PIN: N/A
Carrier: ChinaMobile
Posts: 55
Default

Hi,
to avoid the menu to appear you can give the button a certain style when creating it. (in this case CONSUMECLICK):
new ButtonField("submit",ButtonField.CONSUME_CLICK);

To run one of the standard BB-apps there is the INVOKE class.
you can start the the calander with:

Invoke.invokeApplication(Invoke.APP_TYPE_CALENDER, new CalendarArguments(ARG_VIEW_DAY , Calendar date) );

you can start the calander in different views (see api)

hf
J

Last edited by jenselense; 12-17-2007 at 01:29 AM..
Offline  
Old 12-17-2007, 07:06 PM   #11
kazack
New Member
 
Join Date: Dec 2007
Model: 8320
PIN: N/A
Carrier: tmobile
Posts: 11
Default

Quote:
Originally Posted by jenselense View Post

Invoke.invokeApplication(Invoke.APP_TYPE_CALENDER, new CalendarArguments(ARG_VIEW_DAY , Calendar date) );


hf
J
I thank you so very much for your information. I did find the api call that you mention above. But I guess my next question is sending the Calendar date??

What format does that need to be in MM/DD/YY MM/DD/YYYY MM-DD-YY, MM-DD-YYYY, or just MMDDYY or MMDDYYYY and being I am sending a string value I would assume I do not need quotes around it, or does it need to be a Date Variance andnot a string or integer?

Thanks Alot for the help,
Shawn
Offline  
Old 12-18-2007, 04:23 AM   #12
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

java.util.Calendar

hth,
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Johnson Controls Metasys XP-9102-8304 Expansion Module XP9102 (New/Open Box) picture

Johnson Controls Metasys XP-9102-8304 Expansion Module XP9102 (New/Open Box)

$149.99



Johnson Controls A421abc-04C Electronic Temperature Control, Open/Close On picture

Johnson Controls A421abc-04C Electronic Temperature Control, Open/Close On

$108.99



Johnson Controls MS-VMA1630-1 VMA ProgrammableVAV Box Controller picture

Johnson Controls MS-VMA1630-1 VMA ProgrammableVAV Box Controller

$255.00



Johnson Controls NSB8BTN240-0 Network Sensor - NEW IN FACTORY SEALED BOX picture

Johnson Controls NSB8BTN240-0 Network Sensor - NEW IN FACTORY SEALED BOX

$72.95



Johnson Controls NS-BTP7001-0 Network Sensor Temp Adjustment Modular Jack picture

Johnson Controls NS-BTP7001-0 Network Sensor Temp Adjustment Modular Jack

$79.00



Johnson Controls NSB8BTN240-0 Network Sensor (New in Box) picture

Johnson Controls NSB8BTN240-0 Network Sensor (New in Box)

$74.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.