In Listfield not able to view the fields in blackberry - blackberry

i have tried this link How to customize a ListField in BlackBerry? to create the ListField with Three lablefields for every list row.but iam not able see the list field items.but i can say that listfield is added.because on navigation click i am able get the selected index of the listfield.please anybody help where iam doing mistake.The code i have tried is...
public class InboxWithOutCheckboxeslistfield extends ListField implements ListFieldCallback {
private Vector rows;
private TableRowManager row ;
private LabelField UserName,Message,Timestamp;
/**
* Creates a new MyScreen object
*/
public InboxWithOutCheckboxeslistfield() {
// TODO Auto-generated constructor stub
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setCallback(this);
rows = new Vector();
for (int x = 0; x < 10; x++) {
row = new TableRowManager();
UserName = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.LEFT);
UserName.setText("name");
row.add(UserName);
Message = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Message.setText("hai");
row.add(Message);
Timestamp = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Timestamp.setText("hai");
row.add(Timestamp);
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
// TODO Auto-generated method stub
InboxWithOutCheckboxeslistfield list = (InboxWithOutCheckboxeslistfield) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width, list.getRowHeight());
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return null;
}
public int getPreferredWidth(ListField listField) {
// TODO Auto-generated method stub
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
private class TableRowManager extends Manager {
protected TableRowManager(){super(0);
// TODO Auto-generated constructor stub}
}
public void drawRow(Graphics graphics, int i, int y, int width,
int rowHeight) {
// TODO Auto-generated method stub
// Arrange the cell fields within this row manager.
layout(width, rowHeight);
// Place this row manager within its enclosing list.
setPosition(i, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
graphics.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(graphics);
graphics.setColor(0x00CACACA);
graphics.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
graphics.popContext();
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the list name label field
field = getField(1);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the due time name label field
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(getPreferredWidth(), getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth()
{
return getWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight()
{
return getHeight();
}
}
protected boolean navigationClick(int status, int time) {
int index1 = getSelectedIndex();
System.out.println("The Clikced item is:"+index1);
return true;
}
}
and the mainscreen class is
public class InboxWithOutCheckboxes extends MainScreen{
private InboxWithOutCheckboxeslistfield inboxWithOutCheckboxeslistfield;
public InboxWithOutCheckboxes(){
super();
inboxWithOutCheckboxeslistfield = new InboxWithOutCheckboxeslistfield();
add(inboxWithOutCheckboxeslistfield);
add(new SeparatorField());
}
}

Try This code -
Add lists on Main Screen-
InboxWithOutCheckboxeslistfield InboxWithOutCheckboxeslistfield = new InboxWithOutCheckboxeslistfield ();
add(InboxWithOutCheckboxeslistfield );
add(new SeparatorField());
Click event listener of list -
protected boolean navigationClick(int status, int time) {
getValue();
return true;
}
protected void getValue() {
Field f = getFieldWithFocus();
if (f instanceof ListField) {
ListField l = (ListField) f;
final int index = l.getSelectedIndex();
FriendsRequestObject _contactslist = (FriendsRequestObject) FriendsRequest_fields.vector.elementAt(index);
final String _name = _contactslist.getSender_name();
final String _id = _contactslist.getSender_id();
//Dialog.alert(_name);
Application.getApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(_name);
}
});
// Dialog.alert("The selected element is: "+Integer.toString(l.getSelectedIndex()));
}
}
import java.util.Vector;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
class InboxWithOutCheckboxeslistfield extends ListField implements ListFieldCallback {
private Vector contacts;
static Vector vector = new Vector();
private int contactslist_size = 0;
private String name_ = "", id_="", status_="";
public InboxWithOutCheckboxeslistfield () {
super(0, ListField.MULTI_SELECT);
setRowHeight(60);
setEmptyString("Empty List", DrawStyle.HCENTER);
setCallback(this);
contacts = new Vector();
vector.addElement(new FriendsRequestObject("1", "hai1", ""));
vector.addElement(new FriendsRequestObject("2", "hai2", ""));
vector.addElement(new FriendsRequestObject("3", "hai3", ""));
vector.addElement(new FriendsRequestObject("4", "hai4", ""));
contactslist_size = vector.size();
for (int x = 0; x < contactslist_size; x++) {
FriendsRequestObject b = (FriendsRequestObject) vector.elementAt(x);
id_ = b.getSender_id().toString();
name_ = b.getSender_name().toString();
status_ = b.getimage().toString();
TableRowManager row = new TableRowManager() {
public void paint(Graphics g) {
g.setBackgroundColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
g.clear();
super.paint(g);
}
};
LabelField name1 = new LabelField(id_, DrawStyle.ELLIPSIS);
name1.setFont(Font.getDefault().derive(Font.PLAIN));
row.add(name1);
LabelField name = new LabelField(name_, DrawStyle.ELLIPSIS);
name.setFont(Font.getDefault().derive(Font.PLAIN));
row.add(name);
// add to the table
contacts.addElement(row);
}
setSize(contacts.size());
}
// ListFieldCallback Implementation
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
InboxWithOutCheckboxeslistfield list = (InboxWithOutCheckboxeslistfield ) listField;
TableRowManager rowManager = (TableRowManager) list.contacts.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
// Causes the fields within this row manager to be layed out then
// painted.
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
// Place this row manager within its enclosing list.
setPosition(x, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
g.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
// Arrages this manager's controlled fields from left to right within
// the enclosing table's columns.
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
/* positioning of fields in list */
// Status
Field field = getField(0);
layoutChild(field, preferredWidth, 50);
setPositionChild(field, 10, 5);
// Name
field = getField(1);
layoutChild(field, 150, fontHeight + 1);
//setPositionChild(field, 1, 2);
setPositionChild(field, 80, fontHeight );
setExtent(preferredWidth, getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
FriendsRequestObject is given below -
public class FriendsRequestObject {
private String sender_id;
private String sender_name;
private String image;
public FriendsRequestObject(String sender_id, String sender_name, String image){
this.sender_id = sender_id;
this.sender_name =sender_name;
this.image =image;
}
public String getimage() {
return image;
}
public void setimage(String image) {
this.image = image;
}
public String getSender_id() {
return sender_id;
}
public void setSender_id(String sender_id) {
this.sender_id = sender_id;
}
public String getSender_name() {
return sender_name;
}
public void setSender_name(String sender_name) {
this.sender_name = sender_name;
}
}

Edit your implementation of TableRowManager. You need to change the getPreferredWidth(), and getPreferredHeight(). getWidth() and getHeight() will return wrong value if the sublayout() method execution doesn't finish earlier.
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return Display.getWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return getRowHeight();
}

Related

How can i select a drop down which i added over a list field?

Hi Friend's in my BlackBerry Application i use a list Field, and over this list Field i add a drop down. Now my problem is how do i select the drop down which i added over the list Field.Now i only select list field and not the drop down but my requirement is first i should select the drop down and then list field. I have included my code here please check it.
public class TaskListField extends ListField implements ListFieldCallback, KeypadListener {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
public LoginPage objLoginPage;
public String[] data={"Call","Visit"};
public String strIndex = null;
public int tempIndex = 0;
public int intvalue;
public int id;
public int value;
public boolean hasFocus = false;
public static String[] arrOutletName = { "Dosa Store", "Benfish Bhawan",
"Nalban Park", "Korunamoyee", "206 Bus Stop", "aaaaaaaa",
"bbbbbbbb", "ccccccccc", "dddddddd", "eeeeeee" };
public ObjectChoiceField ocf;
public TaskListField() {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
setCallback(this);
p1 = Bitmap.getBitmapResource("name.png");
p2 = Bitmap.getBitmapResource("name.png");
rows = new Vector();
for (int x = 0; x < XmlHander.vectSrno.size(); x++) {
TableRowManager row = new TableRowManager();
strIndex = String.valueOf(x);
String strVectno = XmlHander.vectSrno.elementAt(x).toString();
String strSLADate = XmlHander.vectSldate.elementAt(x).toString();
if (x % 2 == 0) {
row.add(new BitmapField(null));
}
else {
row.add(new BitmapField(null));
}
LabelField task = new LabelField(" ");
if (x % 15 == 0) {
task.setFont(Font.getDefault().derive(Font.BOLD | Font.UNDERLINED));
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
}
row.add(task);
row.add(new LabelField(strVectno, DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
// graphics.setColor(Color.PINK);
super.paint(graphics);
}
});
row.add(ocf=new ObjectChoiceField("",data){
protected void paint(Graphics graphics){
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
ocf.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
if(context != PROGRAMMATIC)
Dialog.alert(data[ocf.getSelectedIndex()]);
}
});
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
TaskListField list = (TaskListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
protected boolean navigationClick(int status, int time) {
final int index;
index = this.getFieldWithFocusIndex() - 1;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new Details(id));
}
});
return false;
}
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
id = this.getSelectedIndex();
invalidate();
return super.moveFocus(amount, status, time);
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
System.out.println("direction==" + direction);
invalidate();
}
public void onUnfocus() {
updateLayout();
super.onUnfocus();
invalidate();
}
private int getFieldWithFocusIndex() {
return 0;
}
}

How to create a custom drop down in blackberry

Can anyone please help me to create a custom drop down similar to the image attached in blackberry 5.0. I have used object choice field but it is coming along with label. Guide me to create custom drop down as show in image below
I have created my customized ChoiceField, using popup Screen. Here is the below code sample
package com.src.java.rim.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class FWCustomChoiceField extends HorizontalFieldManager {
/*space between text and icon*/
final int padding = 10;
String arrowBitmapName = "arrow_state_grey_right.png";
Object choice[] = null;
int index = -1;
String text = "Please select one option";
ListField choiceField = null;
public FWCustomChoiceField(final Object choice[]) {
this.choice = new Object[choice.length];
this.choice = choice;
choiceField = new ListField(){
protected boolean navigationClick(int status, int time) {
Field focus = UiApplication.getUiApplication().getActiveScreen() .getLeafFieldWithFocus();
if (focus instanceof ListField) {
ChoicePopupScreen popup = new ChoicePopupScreen(10, 80, choice);
popup.setChoice(choice);
UiApplication.getUiApplication().pushScreen(popup);
}
return super.navigationClick(status, time);
}
};
choiceField.setSize(1);
choiceField.setCallback(new TestListCallback());
add(choiceField);
}
public void setSelIndex(int index){
this.index = index;
this.text = choice[index].toString();
choiceField.invalidate();
}
public int getSelectedIndex(){
return index;
}
final class TestListCallback implements ListFieldCallback {
TestListCallback() {
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
Bitmap bitmap = Bitmap.getBitmapResource(arrowBitmapName);
int fontWidth = getFont().getAdvance(text);
int width = Display.getWidth() ;
int posX = (width-(fontWidth + padding + bitmap.getWidth()))/2;
int height = list.getRowHeight();
int posY = (height - bitmap.getHeight())/2;
g.drawText(text, posX, y, 0, w);
g.drawBitmap(posX+fontWidth+padding,posY, bitmap.getWidth(), bitmap.getHeight(), bitmap, 0, 0);
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return Graphics.getScreenWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return listField.indexOfList(prefix, start);
}
}
public class ChoicePopupScreen extends PopupScreen {
Object []choice = null;
/*holds the position for popup screen*/
private int _posX = 0;
private int _posY = 0;
public ChoicePopupScreen(int posx,int posy, Object[] choice) {
/*calling super class constructor*/
super(new VerticalFieldManager(), Field.FOCUSABLE);
this.setMargin(new XYEdges(1,1,1,1));
this.choice = new Object[choice.length];
this.choice = choice;
/*Setting position for popup screen*/
_posX = posx;
_posY = posy;
/*list field customized to display as choice picker*/
ListField choiceList = new ListField(){
/*list field event handling using navigation click*/
protected boolean navigationClick(int status, int time) {
/*getting the selected list index value*/
int index = this.getSelectedIndex();
/*returning the selected index to the main field*/
setSelIndex(index);
/*removing the popup screen from the screen stack*/
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
/*required for event handling*/
return super.navigationClick(status, time);
}
};
/*displays the message when list is empty*/
choiceList.setEmptyString("List is empty", DrawStyle.LEFT);
choiceList.setSize(choice.length);
choiceList.setCallback(new PopUpListCallback());
add(choiceList);
Border border = BorderFactory.createSimpleBorder( new XYEdges(), Border.STYLE_TRANSPARENT);
this.setBorder(border);
}
protected void setChoice(Object []choice) {
this.choice = new Object[choice.length];
this.choice = choice;
}
protected void sublayout(int width, int height) {
super.sublayout(width, height);
/*setting the position for the popup screen*/
setPosition(_posX , _posY);
}
}
private class PopUpListCallback implements ListFieldCallback {
PopUpListCallback() {
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
String text = choice[index].toString();
g.drawText(text, padding, y, 0, w);
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return Graphics.getScreenWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return listField.indexOfList(prefix, start);
}
}
}
To use the above class
String choicestrs[] = {"Opt 1", "Opt 2", "Opt 3"};
add(new FWCustomChoiceField(choicestrs));

BlackBerry - How to add clickEvent (setChangeListener) to ListField in BlackBerry?

I'm using ListField in Blackberry and unable to apply the row.setChangeListener.
Can anybody please help me?
Here is my code,
Friendship objFriendship = new Friendship();
friends = objFriendship.FetchFriends(AATTGlobals.CURRENT_USER.getUserID());
rows = new Vector();
for (int x = 0; x < friends.length; x++) {
String UserName = friends[x].getUserName();
ProfilePicture = MISC.FetchUserProfilePicture(friends[x].getProfilePicturePath());
String Location = friends[x].getLocation();
TableRowManager row = new TableRowManager();
row.add(new BitmapField(ProfilePicture));
LabelField task = new LabelField(UserName,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
};
task.setFont(Font.getDefault().derive(Font.BOLD));
row.add(task);
row.add(new LabelField(Location,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
}
);
row.setChangeListener( new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Row Clicked #");
}
});
No any error message but setChangeListener doesn't fire, here is TableRowManager
Private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x0099CCFF);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 44, 44);
setPositionChild(field, 10, getRowHeight() / 4);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 70, getRowHeight() / 5);
field = getField(2);
layoutChild(field, field.getPreferredWidth(), fontHeight + 1);
setPositionChild(field, 70, (getRowHeight() / 2) + 5);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
in tableRowManager add this
//for non touch
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
//for touch
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
try this let me know is it working or not.
I noticed, fieldChangeLister/FieldChanged isnt getting called with ListField UI [as it works for button and labels.]So I think FieldChanged is not supported with Listfield
In navigationClick/TouchEvent (), write the action you are writing in FieldChange method.

Not showing Transparent background?

Hi developers I have a screen with transparent background(bitmap). I have a list field placed on top of it, but the issue is the transparent background is not showing the previous screen, instead it shows white screen with listfield.
public class IndexScreen extends MainScreen implements ListFieldCallback {
private Vector rows;
ListField listItems;
int listItem;
int listFieldIndex = -1;
TableRowManager row;
Bitmap indexBox = Bitmap.getBitmapResource("res/screens/Index_Box.png");
public IndexScreen() {
listItems = new ListField() {
listItems.setRowHeight(20);
listItems.setCallback(this);
rows = new Vector();
listItems.setSize(rows.size());
_listVfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL) {
public void paint(Graphics g) {
g.drawBitmap(0, 0, UIinitialize.screenWidth,
UIinitialize.screenHeight, indexBox, 0, 0);
super.paint(g);
}
protected boolean navigationMovement(int dx, int dy, int status,
int time) {
return super.navigationMovement(dx, dy, status, time);
}
protected void sublayout(int maxWidth, int maxHeight) {
layoutChild(listItems, maxWidth, maxHeight);
setPositionChild(listItems, 5, 0);
setExtent(maxWidth, 255);
}
};
_listVfm.add(listItems);
add(_listVfm);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
listItems.invalidate();
}
}, 500, true);
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
TableRowManager rowManager = (TableRowManager) rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width, listItems.getRowHeight());
}
class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, 250);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.popContext();
}
protected void sublayout(int width, int height) {
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, preferredWidth, height);
setPositionChild(field, 0, 0);
setExtent(width, height);
}
public int getPreferredWidth() {
return listItems.getWidth();
}
public int getPreferredHeight() {
return listItems.getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
The above code is the part of the code that I am using.How can I implement to view the transparent background.Can anybody please help me.Thanks.
MainScreen includes its own non-transparent background. You'll have to extend Screen if you want to have a transparent/translucent background.
Another option, which I've used in my apps, is using FullScreen instead of MainScreen. FullScreen allows transparent backgrounds. If you're using setStatus or setTitle you'll have to find another method of displaying that data, but otherwise it's very similar.
From your code, though, extending Screen instead of MainScreen would likely by more appropriate.

how to create a list field as same style as BlackBerry facebook?

how to create a list field as same style as Black Berry facebook ?
the RIM list field contains only text, i want to create list field that can contains other fields such as image, text area and href link .
I managed to create it ,and it works fine but the the fields inside the list item never gain focus , any idea how do it ?
public class RichListField extends ListField implements ListFieldCallback {
private Vector rows;
public RichListField(String emtpyString, RichListItem[] items) {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString(emtpyString, DrawStyle.HCENTER);
setCallback(this);
rows = new Vector();
for (int i = 0; i < items.length; i++) {
TableRowManager row = new TableRowManager();
row.add(new BitmapField(items[i].getBitmap()));
LabelField itemLabel = new LabelField(items[i].getLabel(),
DrawStyle.ELLIPSIS);
// mark selected
// itemLabel.setFont(Font.getDefault().derive(
// Font.BOLD | Font.UNDERLINED));
itemLabel.setFont(Font.getDefault().derive(Font.BOLD));
row.add(itemLabel);
// SET THE LIST Item description
row.add(new LabelField(items[i].getDescription(),
DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
row.add(items[i].getLink());
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
RichListField list = (RichListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows
.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
// start with the Bitmap Field of the priority icon
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
// set the label field
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the description label field
field = getField(2);
layoutChild(field, preferredWidth, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the Href field
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
//To set the required dimensions for the field
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Display.getWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
public class RichListItem {
private String label;
private Bitmap bitmap;
private String description;
private HrefField link;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public HrefField getLink() {
return link;
}
public void setLink(HrefField link) {
this.link = link;
}
public RichListItem(String label, Bitmap bitmap, String description,
HrefField link) {
super();
this.label = label;
this.bitmap = bitmap;
this.description = description;
this.link = link;
}
}
You just need to add 2 lines of code at drawListRow when implement interface ListFieldCallback.
if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) rowColor = Color.RED;
else rowColor = Color.GRAY
If all you want to do is change the color when a row has focus, you could override ListField.drawFocus():
protected void drawFocus(Graphics graphics, boolean on) {
if (on) {
graphics.setColor(focusColor);
graphics.setBackgroundColor(focusBackgroundColor);
super.drawFocus(graphics, on);
/**
You may have to play with the call to super.drawFocus() depending on
what it actually does. For example:
super.drawFocus(graphics, false);
may work better. Or you may have to draw the field yourself.
*/
}
}

Resources