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 Developer
jahan87
Posts: 13
Registered: ‎12-12-2011
My Device: Blackberyy Bold 9780
Accepted Solution

ArrayList<>

I was developing for android and recenlty started with blackberry. What's the alternate for array list in BB 6.0? My code from android is below:

 

public static ArrayList<Friend> friendList;

public static ArrayList<Friend> SoapGetFriends(SoapObject soap)
{ SoapObject mySoapObject = (SoapObject)soap.getProperty(0);

ArrayList<Friend> friendList = new ArrayList<Friend(mySoapObject.getPropertyCount());

    for (int i = 0; i < mySoapObject.getPropertyCount(); i++) {

    SoapObject mySoapObject2 = (SoapObject)mySoapObject.getProperty(i);
    Friend friend = new Friend();

friend.setFriendID(mySoapObject2.getProperty("FriendID").toString()); friend.setFriendName(mySoapObject2.getProperty("FriendName").toString()); friendList.add(friend); } return friendList; }

 

Any suggestions will be appreciated. :Yes:

Developer
tklanilkumar
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800

Re: ArrayList<>

you can use Vector to store inplace of ArrayList..
*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue
Developer
tklanilkumar
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800

Re: ArrayList<>

you can use following snippent for vector of your code

take the vector and add Friend class object to it like below..


public static Vector SoapGetFriends(SoapObject soap)
{
SoapObject mySoapObject = (SoapObject)soap.getProperty(0);

Vector friendList = new Vector(mySoapObject.getPropertyCount());

for (int i = 0; i < mySoapObject.getPropertyCount(); i++)
{
SoapObject mySoapObject2 = (SoapObject)mySoapObject.getProperty(i);
Friend friend = new Friend();
friend.setFriendID(mySoapObject2.getProperty("FriendID").toString()); friend.setFriendName(mySoapObject2.getProperty("FriendName").toString());
friendList.addElement(friend);
}
return friendList;
}
class Friend
{
public Friend()
{
// TODO Auto-generated constructor stub
}
private String FriendID;
private String FriendName;

public void setFriendID(String friendID) {
FriendID = friendID;
}

public String getFriendID() {
return FriendID;
}

public void setFriendName(String friendName) {
FriendName = friendName;
}

public String getFriendName() {
return FriendName;
}
}

*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue