Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
VimalSandy
Posts: 85
Registered: 07-12-2011
My Carrier: Airtel

How to add String object to String[ ] array.

hi.. i need to display drop down list in my screen.. im using objectchoicefield.. i want to list of String Dynamically..  To Add list String Statically not problem. i can like this

 

String[ ] choice = {"hi","hello","how"," when"};

 

how to add this things dynamically..  pls help out

Please use plain text.
Developer
lakshman9687
Posts: 134
Registered: 07-22-2011
My Carrier: AirTel

Re: How to add String object to String[ ] array.

[ Edited ]

Hi Vimal,

 

You can't add strings dynamically to string array, insted of that u can use StringBuffer or u can use vector.

 

My suggestion is use Vectors ,in that u can add or remove what ever u want....

 

In object choicefield  also write vector.elementAt(index).toString()..

 

Thanks..

Lakshman

----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

Please use plain text.
Developer
jitendrasharma
Posts: 205
Registered: 08-04-2009

Re: How to add String object to String[ ] array.

You can use 

Arrays.add(Object[] arg0, Object arg1);

to add an element to an existing array.

 

Please use plain text.
Developer
tklanilkumar
Posts: 97
Registered: 02-22-2011
My Carrier: idea

Re: How to add String object to String[ ] array.

[ Edited ]

take the array length and give like this
String[ ] choice = new String[length];

now you can add the Strings to that array by this

choice[array_index] = "your required string";


Please use plain text.
Regular Contributor
VimalSandy
Posts: 85
Registered: 07-12-2011
My Carrier: Airtel

Re: How to add String object to String[ ] array.

Thanks for all reply ..

Lakshman9687: in vector i have objects.. how to add to object choicefield.. those objects are strings..


Please use plain text.
Developer
tklanilkumar
Posts: 97
Registered: 02-22-2011
My Carrier: idea

Re: How to add String object to String[ ] array.

get all the elements(here Strings) of the vector and use the objectChiceField.setChoices() method to set the list.
Please use plain text.
Developer
lakshman9687
Posts: 134
Registered: 07-22-2011
My Carrier: AirTel

Re: How to add String object to String[ ] array.

Hi,

 

Vector v = new Vector();

v.addElement();.....

ObjectChoiceField obj = new ObjectChoiceField();

 

 

        String s[] = new String[v.size()];
        for(int i =0; i < v.size(); i++)
        {
            s[i] = v.elementAt(i).toString();
        }
        obj.setChoices(s);

 

Like this u can add...

 

Thanks,

Lakshman

----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

Please use plain text.
Regular Contributor
VimalSandy
Posts: 85
Registered: 07-12-2011
My Carrier: Airtel

Re: How to add String object to String[ ] array.

Thanks for reply..
i got the solution..

public void addStringElement(String[] arr, int pos, String name){
String[] copy = new String[arr.length+2];

System.arraycopy(arr,0,copy,0,arr.length);

copy[pos] = name;
System.arraycopy(copy,0,arr,0,arr.length);


}
Please use plain text.