02-08-2010 01:06 PM
Hi
I am new to Blackberry development environment and I am trying to develop an App containing one screen with List of Text items (List element). I am reading lot of development guides, I am clueless in how to implement ListCallback.
Can one help me regarding the same (like private class ListCallback implements ListFieldCallback )
Thanks & Regards
Siva
Solved! Go to Solution.
02-08-2010 01:16 PM
Hi and Welcome to the forums.
You will find as a new BlackBerry developer, that a lot of your questions will probably have been already asked. So do a search of the forum. It is not that easy to search, so try a number of different keywords if you can.
In this case, if you had searched for "sample listfield", you probably would have found this Thread as the first link.
http://supportforums.blackberry.com/t5/Java-Develo
There are others there as well, but I do think this one will help you.
Hope it does and hope your enjoy you BlackBerry development experience.
02-09-2010 12:54 PM
Thanks. It certainly helped me.
I found that Graphics.getScreenWidth() API is deprecated in Latest version. You have used this your ListCallBack class as follows
public int getPreferredWidth(ListField list) {
return Graphics.getScreenWidth();
}
I found some one is using Dialog.getWidth(); but that is also not there.
Can you help
Thanks
Siva
02-09-2010 01:32 PM - edited 02-09-2010 01:34 PM
I found the below code is working for me (even with Deprecated APIs)
import java.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
public class cList extends UiApplication
{
private ListField myList;
public static void main(String[] args)
{
cList app = new cList();
app.enterEventDispatcher();
}
private static class ListCallback implements ListFieldCallback
{
private Vector listElements = new Vector();
public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
String text = (String)listElements.elementAt(index);
g.drawText(text, 0, y, 0, w);
}
public Object get(ListField list, int index)
{
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s)
{
return listElements.indexOf(p, s);
}
public int getPreferredWidth(ListField list)
{
return Graphics.getScreenWidth();
}
public void insert(String toInsert, int index)
{
listElements.addElement(toInsert);
}
public void erase()
{
listElements.removeAllElements();
}
}
public cList()
{
MainScreen mainScreen = new MainScreen();
myList = new ListField();
ListCallback myCallback = new ListCallback();
myList.setCallback(myCallback);
String fieldOne = "ListField one";
String fieldTwo = "ListField two";
String fieldThree = "ListField three";
myList.insert(0);
myCallback.insert(fieldOne, 0);
myList.insert(1);
myCallback.insert(fieldTwo, 1);
myList.insert(2);
myCallback.insert(fieldThree, 2);
mainScreen.add(myList);
mainScreen.setTitle(": This is Heading of List :");
pushScreen(mainScreen);
}
}
02-09-2010 02:36 PM - edited 02-09-2010 02:39 PM
You are right, the
Graphics.getScreenWidth();
should be replaced with
Display.getWidth();
Glad you got it going.
BTW, did you read right to the end of the Thread. There is an example I put at the end that uses ListField in a different (and I think easier to understand) way.
02-10-2010 11:07 AM
Yes, I got what you are referring and I am able to run with that code also. Thanks for the same.
This triggered me two more questions
Question 1:
How to display a list with an ICON, Name and a small Icon.
If I compare single Line of a List to a printf, I want to have a class which accepts variable parameters and types as follows
printf("%LICON %s %SICON",1.png, "hello", 2.png);
LICON and SICON are different differentiators.
Question 2:
How to send List data from one Application/Thread to another Application/Thread respectively.
Thanks
Siva
02-10-2010 11:47 AM
1. This is relatively easy, but you have to do the formatting yourself. So if you have an icon, your use grpahics.drawbitmap in your drawListRow method to draw this, then start your drawText a bit further along so it doesn't draw over the icon.
2. Are these programs in the same application? If so, then use the standard Java mechanisms. If not, then search the forum for IPC (Inter Process Communication), as this question has been asked before.
02-10-2010 12:47 PM
Thanks peter (hope I can call you as peter) for your quick response and help
Thanks & Regards
Siva