BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 08-01-2005, 08:06 PM   #1
timinator
Knows Where the Search Button Is
 
timinator's Avatar
 
Join Date: Jul 2005
Location: Washington
Model: 8300
Carrier: AT&T
Posts: 29
Default Example of Edit Fields and Buttons

Please Login to Remove!

I've been asking my share of "rookie" Blackberry questions here, and some of what I've found has been helpful and some has not. There seems to be a big gap between the "Hello World" and the UI samples in the docs and on the forums. So, I figured I would post a small sample that demonstrates how to display Input fields and buttons, and how to show the contents of the Input fields when specific buttons are clicked. Feel free to comment on and make improvements. Here's the code:

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

// MyTextInput2.java Class --------------------------------------------------------------------------
public class MyTextInput2 extends net.rim.device.api.ui.UiApplication implements FieldChangeListener
{
    private AutoTextEditField inputField;                   //define the edit fields
    private AutoTextEditField anotherField;
    private LabelField appTitle;                            //application title label
    private ButtonField showInputButton;                    //define the buttons
    private ButtonField anotherInputButton;
    
    public static void main(String[] args)
    {
        MyTextInput2 TIinstance = new MyTextInput2();       //create an instance of this class app
        TIinstance.enterEventDispatcher();                  //define a handle for the event processor
    }
    
    public MyTextInput2()
    {
        MainScreen inputScreen = new MainScreen();          //create screen instance
        appTitle = new LabelField("Input Test2");           //define app title
        inputField = new AutoTextEditField("Input1: ","");  //define edit fields
        anotherField = new AutoTextEditField("Input2: ","");
        showInputButton = new ButtonField("Show Input1 value");     //define button titles
        anotherInputButton = new ButtonField("Show Input2 value");
        showInputButton.setChangeListener(this);            //define the button handles for the event processor
        anotherInputButton.setChangeListener(this);
        inputScreen.setTitle(appTitle);                     //post the screen title
        inputScreen.add(inputField);                        //post the input fields on screen
        inputScreen.add(anotherField);
        inputScreen.add(showInputButton);                   //post the buttons on the screen
        inputScreen.add(anotherInputButton);            
        pushScreen(inputScreen);                            //post the screen itself
    }

    public void fieldChanged(Field field, int context) //respond to button events
    {
        if (field == showInputButton) //if first button selected
        {
            Dialog.alert(inputField.getText()); //show text from first input field
        }
        if (field == anotherInputButton) //if second button selected
        {
            Dialog.alert(anotherField.getText()); //show text from second input field
        }
    }
    
    public boolean onClose() //fires if app is closed
    {
        Dialog.alert("Exiting.");
        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  
Old 08-03-2005, 11:43 AM   #2
Learner
Knows Where the Search Button Is
 
Join Date: Feb 2005
Location: New Mexico
Posts: 26
Default

Thanks. I noticed an option in the menu to save, but this wasn't implemented. How to save this data?
Offline  
Old 08-03-2005, 11:53 AM   #3
corey@12mile
BlackBerry Extraordinaire
 
Join Date: Dec 2004
Location: in a house...
Model: lots
Carrier: Rogers
Posts: 1,148
Default

Good example, you might want to override the trackwheelListener. As well, you don't need to enter the entire class path for the class.

Code:
public class MyTextInput2 extends UiApplication implements FieldChangeListener
would be sufficient.

What I like to do is override the FieldChangeListener on each button individually like this...

Code:
ButtonField testButton = new ButtonField("Click Me");
    testButton.setChangeListener(new FieldChangeListener() 
    {
        public void fieldChanged(Field field, int context) 
        {
             Dialog.alert("Button Clicked!");
        }
    });
It helps me keep the code for the event close to the button object.

cd.
Offline  
Old 08-14-2005, 05:52 PM   #4
asc1998
Knows Where the Search Button Is
 
Join Date: Feb 2005
Posts: 18
Talking

I am not sure I like either one of these approaches. The first one does not allow me to encapsulate the screen object. The application could get very ugly if it had several screens with all of the objects declared global to the application class.

The second approach (I am not sure about this) appears that the fieldChanged method call would not have access to any of the other objects that are on the screen. Is this the case? Could the fieldChanged method see other fields that are implemented on the main screen to get to their data?

The good thing is it is possible to implement the fieldChangedListner on a subclass of MainScreen. This would allow multiple screens to exist within an application. The screen would then be encapsulated.

Guess its good there is so much flexibility here regarding how to implement this.
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


Chroma A615003 AC Voltage Transform Unit picture

Chroma A615003 AC Voltage Transform Unit

$1100.00



Phoenix Contact Voltage Distribution Block Part No. 2315269 picture

Phoenix Contact Voltage Distribution Block Part No. 2315269

$30.00



(5) MicroChip MCP1700-3302E/TO Fixed 3.3V LDO Voltage Regulators - USA Shipping picture

(5) MicroChip MCP1700-3302E/TO Fixed 3.3V LDO Voltage Regulators - USA Shipping

$6.95



DC 12V TO 48V STEP UP DC CONVERTER VOLTAGE REGULATOR BOOST MODULE picture

DC 12V TO 48V STEP UP DC CONVERTER VOLTAGE REGULATOR BOOST MODULE

$63.45



Renogy 500A Battery Monitor High and Low Voltage Programmable Alarm 500A Shunt picture

Renogy 500A Battery Monitor High and Low Voltage Programmable Alarm 500A Shunt

$85.59



USB Type C Multimeter Current Meter Voltmeter Voltage Digital Tester Detector US picture

USB Type C Multimeter Current Meter Voltmeter Voltage Digital Tester Detector US

$18.90







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