BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-25-2005, 08:55 PM   #1 (permalink)
Knows Where the Search Button Is
 
timinator's Avatar
 
Join Date: Jul 2005
Location: Washington
Model: 8300
Carrier: AT&T
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to determine which button is clicked?

Please Login to Remove!

I'm a rookie at the BB stuff but an experienced developer. In looking at the samples and doing searches via Google, I've yet to come across an example of how to determine which of two buttons have been clicked with the trackwheel. I currently have the following code, modified from the Hello World sample:

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

class SalutationScreen extends MainScreen
{
public SalutationScreen()
{
super();
LabelField applicationTitle = new LabelField("Hello World Title");
ButtonField testButton = new ButtonField("Click Me", FOCUSABLE);
ButtonField orButton = new ButtonField("Or Me", FOCUSABLE);
setTitle(applicationTitle);
add(testButton);
add(orButton);
}
public boolean onClose()
{
Dialog.alert("Bye World!");
System.exit(0);
return true;
}
// Invoked when the trackwheel is clicked.
public boolean trackwheelClick( int status, int time )
{
Dialog.alert("Button clicked. Status:" + status) ;
return true;
}
}


Along with the associated HelloWorld.java routine. How do I determine which button was clicked?

Thanks in advance for the help.

Tim
__________________
===================================
"There are 10 types of people in the world.
Those that understand binary and those that don't!"
www.timothytrimble.info - The ART of S/W Development
==================================
Offline  
Old 07-26-2005, 05:41 AM   #2 (permalink)
New Member
 
Join Date: Jul 2005
Model: 7100T
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

use a field change listener.
Offline  
Old 07-26-2005, 01:02 PM   #3 (permalink)
Knows Where the Search Button Is
 
timinator's Avatar
 
Join Date: Jul 2005
Location: Washington
Model: 8300
Carrier: AT&T
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Duh! How about an example? Or at least point me to a sample that demonstrates how this works with multiple buttons.
__________________
===================================
"There are 10 types of people in the world.
Those that understand binary and those that don't!"
www.timothytrimble.info - The ART of S/W Development
==================================
Offline  
Old 07-26-2005, 02:33 PM   #4 (permalink)
Knows Where the Search Button Is
 
timinator's Avatar
 
Join Date: Jul 2005
Location: Washington
Model: 8300
Carrier: AT&T
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I finally figured this out. I'm surprised that something that should be so easy to do was so difficult to figure out. I guess it's due to the fact that I'm a C & C# developer, just now getting into java. Plus, the fact that the BB does things a little differently. Anyway, for the benefit of anyone else trying to figure this out, here's my sample code for determing which button is being selected. Enjoy.

Code:
// HelloWorld.java

class HelloWorld extends net.rim.device.api.ui.UiApplication 
{
    public static void main(String[] args)
    {
        HelloWorld instance = new HelloWorld();
        instance.enterEventDispatcher();
    }  
    public HelloWorld() 
    {
        pushScreen(new SalutationScreen());
    }
}
And here's the 2nd piece:
Code:
//SalutationScreen.java

import net.rim.device.api.ui.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class SalutationScreen extends MainScreen implements FieldChangeListener
{
    ButtonField testButton;
    ButtonField orButton;
    LabelField applicationTitle;
    
    public SalutationScreen()
    {
        super();
        applicationTitle = new LabelField("Hello World Title");
        setTitle(applicationTitle);
        
        testButton = new ButtonField("Click Me");
        testButton.setChangeListener(this);
        add(testButton);
        
        orButton = new ButtonField("Or Me");
        orButton.setChangeListener(this);
        add(orButton);
    }
    
    public void fieldChanged(Field field, int context)
    {
        if (field == testButton)
        {
            Dialog.inform("Click Me Button clicked.");
        }
        if (field == orButton)
        {
            Dialog.inform("Or Me Button clicked.");
        }
    }

    public boolean onClose()
    {
        Dialog.alert("Bye World!");    
        System.exit(0);
           return true;
    }
}
__________________
===================================
"There are 10 types of people in the world.
Those that understand binary and those that don't!"
www.timothytrimble.info - The ART of S/W Development
==================================
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.