BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-05-2010, 08:44 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Call parent method from child. Possible?

Please Login to Remove!

Is there a way to call a method from the parent window from within the child window?

I tried passing "this" to the child (a reference to the parent window) and doing :

parentReference.functionname() from the child but it didn't seem work.

Thanks in advance!
Offline  
Old 02-05-2010, 01:28 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Over 50 people looked at this thread wiht no responses. Should i assume windows cannot communicate with each other?

I've been on google for the last 4 hours and am going crazy :(
Offline  
Old 02-05-2010, 03:27 PM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

I use that technique all the time. What do you mean by "it didn't seem (to) work"?

The windows don't communicate, the objects do controlled by the way their classes are written. It might help if you posted some code, but please read the sticky thread on posting code first.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 02-05-2010, 03:37 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I must be doing it wrong. I have a menu in my parent screen that has this code :

Code:
private MenuItem _addExercise = new MenuItem("Add Exercise", 200000, 10) {
            public void run()
            {
                AddExerciseScreen addExerciseScreen = new AddExerciseScreen(myMainScreen);
                UiApplication.getUiApplication().pushModalScreen(addExerciseScreen);
            }
    };
(note: I declaire private MainScreen myMainScreen = this; at the top of my parent screen)


Then in the "AddExerciseScreen" inside it's constructor I do this :

Code:
AddExerciseScreen(MainScreen obj) {
        // set the title
        this.setTitle("Add Exercise Item");
        obj.blah();
In the parent screen I have this function :

Code:
  public void blah() {
        System.out.println("************************************************************************");
    }
It gives me the error :

Code:
C:\Fitness_Tracker\AddExerciseScreen.java:37: cannot find symbol
symbol  : method blah()
location: class net.rim.device.api.ui.container.MainScreen
        obj.blah();
Obviouslty it isn't finding the function blah() from within the child... Should I be passing in the mainscreen object to the child?

Last edited by RyanRitten : 02-05-2010 at 03:40 PM.
Offline  
Old 02-05-2010, 06:27 PM   #5 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

MainScreen does not have a method called blah(). This is what the compiler is telling you.

If you are going to do it this way, then you will need to cast that MainSCreen to whatever your screen class is.

OR...make the parameter your mainscreen subclass, instead of MainScreen.
Offline  
Old 02-08-2010, 09:40 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Cool

What do you mean I need the cast it to whatever the screen class is?

I have my blah() method within this class (which is the parent class I described earlier) :

Code:
class HomeScreen extends MainScreen {
...
...
HomeScreen() {
        myMainScreen = this;
        this.setTitle("Fitness Tracker for "+theDate);
}
...
 public void blah() {
        System.out.println("*****************************************");
    }
...
I pass in "myMainScreen" to the new window I open up.

Thanks in advance! I've been stuck on this for a week now. any help is greatly appreciated!!
Offline  
Old 02-08-2010, 10:21 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh wow. I got it working! Thanks Dougsg38p for your help. Using your advice, I made "myMainScreen" of type HomeScreen instead of MainScreen and it worked

ty!!
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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