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
Posts: 3
Registered: ‎02-11-2013
My Device: Blackberry 9300
My Carrier: Movistar

Create Lists

Hi!

I want to create a list with several QR barcodes which i scan with the camera of the device. I assign  the result of the scanned QR to a variable which is a String. I want to use it in a different class, I manage to get the variable in the other class, but I cannot add this variable to a List Field using Vector. I tried with this code but it doesn´t work:

 

Prueba2 objeto = new Prueba2();
qr = objeto.getVariable();// the variable of another class

_listElements = new Vector();
_listElements.addElement(qr);
_listField = new ListField(0,ListField.USE_ALL_WIDTH);
ListCallback _callback = new ListCallback();
_listField.setCallback(_callback);

 

int size = _callback.size();

 

for (int i = 0; i < size; ++i)
{
String res = (String)_listElements.elementAt(i);
// _listField.insert(i);
_listElements.insertElementAt(res, i);
}

add(_listField);

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Create Lists

welcome to the support forums.

i would suggest that you start with a listfield sample and modify it step for step to fit your needs, this way you will see easily where an issue occurs.

in your code you iterate over the callback size, but this would be 0 as there are no elements added.
----------------------------------------------------------
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.
@SimonHain on twitter
Highlighted
New Developer
Posts: 3
Registered: ‎02-11-2013
My Device: Blackberry 9300
My Carrier: Movistar

Re: Create Lists

I tried with this code and I know that size of Vector is always 1, because we scan one QR at a time. Now we iterate from 0 to 1, but I can´t insert the next scanned QR  at the next position of the list, it always override the previous item on the list. 

Please help us cause we are very new with mobile development. Thanks a lot!!

 

Prueba2 objeto = new Prueba2();
qr = objeto.getVariable();

_listElements = new Vector();
_listElements.addElement(qr);
_listField = new ListField(0,ListField.USE_ALL_WIDTH);
ListCallback _callback = new ListCallback();
_listField.setCallback(_callback);

int size =_listElements.size();
LabelField dato = new LabelField("El tamaño del vector es: " + size);
add(dato);

boolean vacio = _listField.isEmpty();
if (vacio == true) {
LabelField dato1 = new LabelField("lista vacía");
add(dato1);
} else {
LabelField dato2 = new LabelField("lista no vacía");
add(dato2);
}


for(int i = 0; i < size ; i++)
{
if (_listField.isEmpty()) {
_listField.insert(i);
_listElements.insertElementAt(qr,i);
} else {
_listField.insert(i++);
_listElements.insertElementAt(qr,i++);
}
}

add(_listField);