Simple List UI using the Blackberry SDK

Simple List UI using the Blackberry SDK

Sample ObjectListField

You want to develop complex lists on the Blackberry? By far, the easiest way to do this is to use the ObjectListField.

Here is an ObjectListField that displays a graphic and a text message:

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ObjectListField;

public class MainMenuList extends ObjectListField {

int _offset = Display.getWidth() / 2;
int _height = 27;

public void drawListRow(ListField list, Graphics g, int i, int y, int w) {
MainMenuData rowData = (MainMenuData)get(list, i);
setRowHeight(_height);
// I want a gray highlight, not the default blackberry blue.
if(list.getSelectedIndex() == i)
{
g.setColor(0xCFCFCF);
g.fillRect(0,(i*_height),Display.getWidth(),_height);
g.setColor(0x000000);
}
else {
g.setColor(0xFFFFFF);
g.fillRect(0,(i*_height),Display.getWidth(),_height);
g.setColor(0x000000);
}
g.drawBitmap(_offset - 80, y, rowData.getBitmap().getWidth(), rowData.getBitmap().getHeight(), rowData.getBitmap(), 0, 0);
g.drawText(rowData.getText(), _offset - 60 + rowData.getBitmap().getWidth(), y);
}

}

And here is the setup, inside of a class that extends MainScreen:


MainMenuData mmr1 = new MainMenuData("Friends", Bitmap.getBitmapResource("friends.png"));
MainMenuData mmr2 = new MainMenuData("Public", Bitmap.getBitmapResource("world.png"));
MainMenuData mmr3 = new MainMenuData("Popular", Bitmap.getBitmapResource("toprated.png"));
MainMenuData mmr4 = new MainMenuData("Me", Bitmap.getBitmapResource("me.png"));
MainMenuData mmr5 = new MainMenuData("Options", Bitmap.getBitmapResource("options.png"));

MainMenuData[] items = new MainMenuData[] { mmr1, mmr2, mmr3, mmr4, mmr5 };
list.set(items);

add(list);

That’s it.

ObjectListField seems to be overlooked in favor of extending ListField, but to my mind this is much easier to implement.  And when time is money, sometimes easier is best.

Advertisements

5 thoughts on “Simple List UI using the Blackberry SDK

    1. Kevin,

      MainMenuData es una clase que define mi menú personalizado datos. Puede usar su propio menú custom clase aquí.

      – David

      Like

  1. Q pena contigo, quisiera q me ayudaras con algo, soy nuevo en esto de BB, estoy haciendo un proyecto de ejemplo y funciona de la siguiente manera, tengo una clase principal llamada Mam y en ella esta el constructor public Mam y dentro de esta esta el llamado a una clase extend MainScreen llamada MamScreen, en esta clase tengo ps 3 botones q en al dar click en c/u me lleva a una nueva vista (vista1,vista2,vista3), lo q quiero hacer es q lo q tienes en tu ejemplo me aparezca cuando de click en uno de los botones, osea al dar click me aparezca esta lista con imagen y con texto, como puedo hacer esto, te agradeceria mucho la ayuda

    Like

  2. Kevin,

    I’m sorry – but my blog really isn’t a support site. I suggest you visit the official Blackberry forum for development questions, especially when beginning BB development in general.

    I don’t really speak or write Spanish well, but can meddle through if I need to. I speak English as my native language.

    Good luck with your project.

    Like

    1. Hi David, I wish implement a List that get Strings parameters of Chat Jabber, now my problem is that I wish view this List in a EditText in other class that extendes Main Screen, I search in blackberry documentation but I don´t see any response. Thanks.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s