Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 2
Registered: ‎05-24-2010
My Device: 8330
My Carrier: Sprint
Accepted Solution

Linking EditField into an Array?

Is it possible to have multiple instances of an EditField with the same name and have them stored in an array?  My problem is I need the user to be able to enter as many times as they need to into a certain field. Ex.  I have a product number field, they could enter one production number, or they could enter 50. So i want something like

 

EditField efProductNumber = new EditField("Product Number:","");

 

add(efProductNumber);

add(efProductNumber);

 

There's some other stuff such as a listener to do another add(efProductNumber) field so I'd like to be able to create the fields on the fly as needed.

 

Any ideas?

 

ZC

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Linking EditField into an Array?

Not making much sense to me, if I understand the question.

 

You cannot add two instances of the same field to the same screen (or different screens, for that matter).

 

My suggestion is that you have one field, and store multiple results from the field in your array (or wherever).

 

Use getText() on the edit field after the user enters the data.

 

 

 

 

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Linking EditField into an Array?

Welcome to the forums!

 

I guess you have some kind of misconception about the "name of the field" - there is no such thing!  There might be a variable/class member named efProductNumber, but all it does is hold a reference to an instance of EditField class.

 

What you want to do is probably something like this:

 

Vector productNumbers = new Vector();

EditField efProductNumber;

String number;

...

// in a loop or a repeatedly called method somewhere in the code

 

    efProductNumber = new EditField(...);

    productNumbers.addElement(efProductNumber);

    add(efProductNumber);

 

...

// after the user has entered all codes he/she wanted

for (int i; i < productNumbers.size(); ++i) {

    efProductNumber = (EditField) productNumbers.elementAt(i);

    number = efProductNumber.getText();

    // do something with that number

}

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Contributor
Posts: 2
Registered: ‎05-24-2010
My Device: 8330
My Carrier: Sprint

Re: Linking EditField into an Array?

Awesome, that worked perfectly.  Thanks.

 

ZC