ListField * void *.

Hello

Am reading RSS feeds and display in a listfield.

Suppose that if there is no flow inside, it displays as * void * inside my listfield.

Can I customize this?

Instead of vacuum, I want it to appear as "workflow unavailable"

How to get there?

any idea?

Hello

setEmptyString

public void setEmptyString(ResourceBundleFamily family,                           int id,                           int style)
Defines the string that is displayed when there is no choice.

This setting is less of a priority than ListField.setEmptyString(String,int) .

Parameters:
family -Family of resource bundle.
id -Resource in the bundle ID.
style -Style for the empty string.
Since:
BlackBerry API 3.6.0

setEmptyString

public void setEmptyString(String emptyString,                           int style)
Sets the marker empty string for this field.

Provide this method with a string (and style) that allows to display this field to indicate that this field in the list is empty (for example the string " [Empty] " ""). By default, the style of this string is DrawStyle.HCENTER (i.e. of the horizontally centered text).

Parameters:
emptyString -Vacuum-marker string for this field.
style -Drawing style for the empty-marker string.

Tags: BlackBerry Developers

Similar Questions

  • ListField and table LayoutManager

    Hello.

    I think that maybe that's my problem.

    I make use of this TableLayoutmanager (that I found on this site):

    public class TableLayoutManager extends Manager{ public TableLayoutManager(){ 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); // 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(); } protected void sublayout(int width, int height) { // TODO Auto-generated method stub int preferredWidth = getPreferredWidth(); int preferredHeight = getPreferredHeight(); Field field = getField(0); layoutChild(field, preferredWidth - 110, preferredHeight); setPositionChild(field, 35, 12); field = getField(1); layoutChild(field, 75, preferredHeight); setPositionChild(field, preferredWidth-75, 11); setExtent(preferredWidth, preferredHeight); } 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 getContentHeight(); } }
    

    for this ListField:

    public class MenuListField extends ListField implements ListFieldCallback { /* * This code created based on rtm4bb HomeMenuListField.java */ private Font font; TableLayoutManager[] rows; public MenuListField(){ // this number should be the same with rows = new TableRowManager[7] // or list item in item field wont show super(9); setEmptyString("sorry, No Menu", DrawStyle.HCENTER); setCallback(this); // this row height to show the height setRowHeight(36); font = Font.getDefault(); rows = new TableLayoutManager[9]; // create a table row manager rows[0] = new TableLayoutManager(); // set the menu item name rows[0].add(new RichTextField("Computer Literacy", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[0].add(new LabelField("All our Computer Literacy Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[0].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[1] = new TableLayoutManager(); // set the menu item name rows[1].add(new RichTextField("Office Assistant", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[1].add(new LabelField("Secretarial Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[1].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[2] = new TableLayoutManager(); // set the menu item name rows[2].add(new RichTextField("Pastel", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[2].add(new LabelField("Pastel Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[2].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[3] = new TableLayoutManager(); // set the menu item name rows[3].add(new RichTextField("Technical", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[3].add(new LabelField("Technical Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[3].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[4] = new TableLayoutManager(); // set the menu item name rows[4].add(new RichTextField("Graphic Design", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[4].add(new LabelField("Graphic Design Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[4].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[5] = new TableLayoutManager(); // set the menu item name rows[5].add(new RichTextField("IT", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[5].add(new LabelField("Our IT Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[5].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[6] = new TableLayoutManager(); // set the menu item name rows[6].add(new RichTextField("Web Design", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[6].add(new LabelField("Web Design Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[6].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[7] = new TableLayoutManager(); // set the menu item name rows[7].add(new RichTextField("Programming", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[7].add(new LabelField("Our Programming Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[7].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[8] = new TableLayoutManager(); // set the menu item name rows[8].add(new RichTextField("Business Admin", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[8].add(new LabelField("Business Oriented Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[8].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[9] = new TableLayoutManager(); // set the menu item name rows[9].add(new RichTextField("Two Year", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[9].add(new LabelField("Two Year Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[9].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); } public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) { // TODO Auto-generated method stub MenuListField list = (MenuListField) listField; TableLayoutManager rowManager = list.rows[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 Graphics.getScreenWidth(); } public int indexOfList(ListField listField, String prefix, int start) { // TODO Auto-generated method stub return -1; } protected boolean trackwheelClick(int status, int time) { int index = getSelectedIndex(); // Dialog.inform("Clicked " + Integer.toString(index)); /*if( index == 0 ) { new MenuCategoryController(); } */ switch(index) { case 0: UiApplication.getUiApplication().pushScreen(new ComputerLiteracyScreen()); break; case 1: UiApplication.getUiApplication().pushScreen(new OfficeAssistantScreen()); break; case 2: UiApplication.getUiApplication().pushScreen(new PastelScreen()); break; case 3: UiApplication.getUiApplication().pushScreen(new TechnicalScreen()); break; case 4: UiApplication.getUiApplication().pushScreen(new GraphicDesignScreen()); break; case 5: UiApplication.getUiApplication().pushScreen(new ITScreen()); break; case 6: UiApplication.getUiApplication().pushScreen(new WebDesignScreen()); break; case 7: UiApplication.getUiApplication().pushScreen(new ProgrammingScreen()); break; case 8: UiApplication.getUiApplication().pushScreen(new BusinessAdminScreen()); break; case 9:      UiApplication.getUiApplication().pushScreen(new TwoYearScreen());   break; } return true; } }
    

    And I call it like:

     MenuListField mylist = new MenuListField();
    

    Now my app keeps throwing errors IndexOutOfBounds.

    I've implemented the table layout manager properly?

    Hannes

    In your situation, I think that most of the BlackBerry users expect to see a drill down, where they see a list of courses in a ListField, then click on the course to see more detail for this course in a different window.

  • ListField background color / highlight

    I am creating a ListField with a red background and white text at any time accept for when highlighted.  When highlighted I would like to highlight to change to color pink (text remains black).  In the following code, the background color is still red, however, the highlight is never fired.

    Question = new ListField()
    {

    Boolean _inFocus;

    protected void onFocus (int direction)
    {
    super.onFocus (branch);
    _inFocus = true;
    Super.Invalidate ();
    }

    protected void onUnfocus()
    {
    super.onUnfocus ();
    _inFocus = false;
    Super.Invalidate ();
    }
       
    public void paint (Graphics g)
    {
    g.setBackgroundColor (Color.RED);
    g.setColor (Color.BLACK);
    Super.Paint (g);

    If (_inFocus)
    {
    g.Clear ();
    g.setBackgroundColor (Color.RED);
    Super.Paint (g);
    }
    on the other
    {
    g.Clear ();
    g.setBackgroundColor (Color.PINK;
    Super.Paint (g);
    }
    g.setBackgroundColor (Color.PINK);
    }
    };

    If I remove the line g.setBackgroundColor (Color.RED); the work of highlighting (rose) and the text remains black, the background color of the listfield however goes to white.  Am I miggins something logic here?  Appreciate any comment.  Thank you.

    Kile

    There is a great knowledge base article ListField coloring:

    Create a color ListField

    Study the code and be creative .

    Good luck!

  • Implementing custom listener for ListField

    I'm trying to implement a listener for a custom field I created that would launch a new screen when you click on the field. However, nothing happens when I click on the custom field. I use BlackBerry Java plug-in for Eclipse, JDK 1.3 and JRE 6.0. All my code is attached. MyScreen.java contains the code where I'm trying to implement a function fieldChanged.

    //MyApp.Java
    
    package mypackage;
    
    import net.rim.device.api.system.CodeModuleManager;
    import net.rim.device.api.ui.UiApplication;
    
    /**
     * This class extends the UiApplication class, providing a
     * graphical user interface.
     */
    public class MyApp extends UiApplication
    {
        /**
         * Entry point for application
         * @param args Command line arguments (not used)
         */
        public static void main(String[] args)
        {
            CodeModuleManager.promptForResetIfRequired();
    
            // Create a new instance of the application and make the currently
            // running thread the application's event dispatch thread.
            MyApp theApp = new MyApp();
            theApp.enterEventDispatcher();
        }
    
        /**
         * Creates a new MyApp object
         */
        public MyApp()
        {
            // Push a screen onto the UI stack for rendering.
            pushScreen(new MyScreen());
        }
    }
    
    //MyScreen.java
    
    package mypackage;
    
    import net.rim.device.api.ui.container.*; //for vertical manager
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.Manager;
    //import net.rim.device.api.ui.Screen;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    
    /**
     * A class extending the MainScreen class, which provides default standard
     * behavior for BlackBerry GUI applications.
     */
    public final class MyScreen extends MainScreen
    {
        /**
         * Creates a new MyScreen object
         */
        private CustomField cField;
    
        public MyScreen()
        {
            // Set the displayed title of the screen
            setTitle("My New App");
    
            cField = new CustomField("4.PNG","This is my 4th custom field!!");
            ButtonClickListener listener = new ButtonClickListener();
            cField.setChangeListener(listener);
            add(cField);
    
        }//MyScreen function
    
        class ButtonClickListener implements FieldChangeListener
        {
            public void fieldChanged(Field field, int context)
             {
                  //we need to determine which button was clicked
    
                  if(field == cField)
                      new SpeedBumpScreen();
    
             }
    
        }//ButtonClickListener
    
    }
    
    //CustomField.java
    
    package mypackage;
    
    import java.util.Vector;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    
    class CustomField extends ListField implements ListFieldCallback {
        private Vector rows;
    
        public CustomField(String customImg, String customLabel) {
            super(0, ListField.MULTI_SELECT);
            setRowHeight(80);
            setEmptyString("Hooray, no items here!", DrawStyle.HCENTER);
            //setCallback(this);
    
            Bitmap p1 = Bitmap.getBitmapResource(customImg); 
    
            rows = new Vector();
    
            TableRowManager row = new TableRowManager();
    
            row.add(new BitmapField(p1));
    
            // SET THE item NAME LABELFIELD
            // if overdue, bold/underline
            LabelField item = new LabelField("item #" + customLabel,
                DrawStyle.ELLIPSIS);
    
            // overdue
            item.setFont(Font.getDefault().derive(
                Font.BOLD | Font.UNDERLINED));
            System.out.println("OVERDUE");
    
            row.add(item);
    
            // SET THE LIST NAME
            row.add(new LabelField("List Name #" + String.valueOf(1),
                DrawStyle.ELLIPSIS) {
                protected void paint(Graphics graphics) {
                    graphics.setColor(0x00878999);
                    super.paint(graphics);
                }
            });
    
            // SET THE DUE DATE/TIME
            row.add(new LabelField("Due Date #" + String.valueOf(1),
                    DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                    | DrawStyle.RIGHT) {
                protected void paint(Graphics graphics) {
                    graphics.setColor(0x00878787);
                    super.paint(graphics);
                }
            });
    
            rows.addElement(row);
    
            setSize(rows.size());
    
        } //end public CustomField()
    
        // ListFieldCallback Implementation
        public void drawListRow(ListField listField, Graphics g, int index, int y,
                int width) {
            CustomField list = (CustomField) listField;
            TableRowManager rowManager = (TableRowManager) list.rows
                .elementAt(index);
            rowManager.drawRow(g, 0, y, width, list.getRowHeight());
        } //end drawListRow()
    
        private class TableRowManager extends Manager {
    
            public TableRowManager() {
                super(0);
            } //end pulic TableRowManager
    
            // 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();
            }//end drawRow()
    
            // Arranges 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();
    
                // start with the Bitmap Field of the priority icon
                Field field = getField(0);
                layoutChild(field, 32, 32);
                setPositionChild(field, 0, 0);
    
                // set the item name label field
                field = getField(1);
                layoutChild(field, preferredWidth - 16, fontHeight + 1);
                setPositionChild(field, 34, 3);
    
                // set the list name label field
                field = getField(2);
                layoutChild(field, 150, fontHeight + 1);
                setPositionChild(field, 34, fontHeight + 6);
    
                // set the due time name label field
                field = getField(3);
                layoutChild(field, 150, fontHeight + 1);
                setPositionChild(field, preferredWidth - 152, fontHeight + 6);
    
                setExtent(preferredWidth, getPreferredHeight());
            }//end sublayout()
    
            // The preferred width of a row is defined by the list renderer.
            public int getPreferredWidth() {
                return Graphics.BLACK;
            }
    
            // The preferred height of a row is the "row height" as defined in the
            // enclosing list.
            public int getPreferredHeight() {
                return getRowHeight();
            }
    
        }// private class TableRowManager extends Manager 
    
        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;
        }
    
    } //end class CustomField extends ListField implements ListFieldCallback
    
    //SpeedBumpScreen.java
    
    package mypackage;
    
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.component.RichTextField;
    import net.rim.device.api.ui.container.MainScreen;
    
    public final class SpeedBumpScreen extends MainScreen
    {
        /**
         * Creates a new HelloWorldScreen object
         */
        SpeedBumpScreen()
        {
            // Set the displayed title of the screen
            setTitle("Speed bump screen");
    
            // Add a read only text field (RichTextField) to the screen.  The
            // RichTextField is focusable by default. Here we provide a style
            // parameter to make the field non-focusable.
            add(new RichTextField("This is the speed bump screen!", Field.NON_FOCUSABLE));
        }
    
    }
    

    In addition, there is nothing in the ListField that will actually generate an event.

    Here is a simple extension to the ListField which will make "clickable".  In your FieldChangeListener you can use getSelectedindex to determine which line has the focus.

    Please ask if this isn't clear:

    public class ClickableListField extends ListField {
    
        public ClickableListField(int numberOfRows) {
            super(numberOfRows);
        }
    
        protected boolean navigationClick(int status, int time) {
            this.fieldChangeNotify(2);
            return true;
        }
    
        protected boolean touchEvent(TouchEvent message) {
            int x = message.getX( 1 );
            int y = message.getY( 1 );
            if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
                    // Outside the field
                    return false;
            }
            // If click, process Field changed
            if ( message.getEvent() == TouchEvent.CLICK ) {
                this.fieldChangeNotify(2);
                return true;
            }
            return super.touchEvent(message);
        }
    
    }
    
  • Touch anywhere on the screen calls the ListField TouchEvent.DOWN

    Hello

    I suffer with small complex issue. In the screen of my application, I have the title bar with a labelfield and two custom buttons.

    Below the titlefield I add a list field.

    Now, I have a few complex features on the field from the list. When I click each line in the list, it should move to another screen I do using navigation, click medium. Now if I touch the rank in the list (for touch devices), it should move to another screen. And if I touch along the line of the list, it will display popup menu (custom, not by default) with option of removal and details.

            mListItem = new ListField(length, ButtonField.CONSUME_CLICK)
            {
                long touchedAt = -1;
                long HOLD_TIME = 500;
    
             // The regular getFieldAtLocation returns wrong values in open
                        // spaces in
                        // complex managers, so we override it
    //                  public int getFieldAtLocation(int x, int y) {
    //                      XYRect rect = new XYRect();
    //                      int index = getFieldCount() - 1;
    //                      while (index >= 0) {
    //                          getField(index).getExtent(rect);
    //                          if (rect.contains(x, y))
    //                              break;
    //                          --index;
    //                      }
    //                      return index;
    //                  }
                protected boolean navigationClick(int status, int time)
                {
                    // Click related functionality
                    return true;
                }
    
                protected boolean touchEvent(TouchEvent message)
                {
                    if(message.getEvent() == TouchEvent.DOWN)
                    {
                         if (getFieldAtLocation(message.getX(1), message.getY(1)) == -1)
                         {
                             Logger.out("AccountList", "Touch down: getField location");
                             return true; // kill the event
                         }
                         else
                         {
                             touchedAt = System.currentTimeMillis();
                             touchedonList = true;
                             Logger.out("AccountList", "Touch down: touched down  "+touchedonList);
                         }
                    }
                    else if(message.getEvent() == TouchEvent.UP )
                    {
    
                           if(System.currentTimeMillis() - touchedAt < HOLD_TIME && touchedonList == true)
                           {
                               touchedAt = -1; // reset
                               // Single Touch and Move to another screen
                           }
    
                           else if(touchedonList == true)
                           {
                             // Showing Menu Popup
                           }
                    }
                    return true;
    //              return super.touchEvent(message);  // Not using this as it will show the default pop up
                }
    

    And here's my reminder list field:

    public class ListCallBack implements ListFieldCallback
        {
            public void drawListRow(ListField listField, Graphics graphics, int index,
                    int y, int width) {
    
                String strdomOrg = yyyyyyy;
                String text = xxxxxx;
                Font f = FONT_FAMILY_0_SF_AS_08;
    
                int h = f.getHeight();
    //          int height = (listField.getRowHeight() - h)/2 ;
                int height = h/2 ;
                y += height;
                graphics.setFont(f);
                graphics.setColor(Color.BLACK);
                graphics.drawText(strdomOrg, 10, y, DrawStyle.ELLIPSIS, width);
                y = y + h;
                graphics.setFont(FONT_FAMILY_1_SF_AS_08);
                graphics.setColor(Color.BLACK);
                graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS , width);
    
             // use the offset instead
                int offset = (listField.getRowHeight() ) >> 1;
                if (index != 0) {
                    graphics.drawLine(0, y - offset , width, y - offset);
                }
            }
    
            public Object get(ListField listField, int index) {
                // TODO Auto-generated method stub
                return mAccounts[index];
            }
    
            public int getPreferredWidth(ListField listField) {
                // TODO Auto-generated method stub
                return screenWidth;
            }
    
            public int getPreferredHeight() {
                return getContentHeight();
            }
    
            public int indexOfList(ListField listField, String prefix, int start) {
                // TODO Auto-generated method stub
                return listField.getSelectedIndex();
            }
    
        }
    

    Now the question is to come a different way:

    1. whenever I touch the buttons in title field, he calls the listfield TouchEvent.DOWN. Then the click of a button does not work. Instead, by clicking on the title bar, it moves to another screen, which is the feature click list filed.

    2. so I added the listfield at a value for money. :

    m_vfmScreen = new VerticalFieldManager(VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR)
            {
    
            protected boolean touchEvent(TouchEvent message) {
                    int event = message.getEvent();
                    if (event == TouchEvent.CLICK) {
                        if (getFieldAtLocation(message.getX(1), message.getY(1)) == -1)
                            return true; // kill the event
                        else {
                        }
                    }
                    return super.touchEvent(message);
                }
    
                // The regular getFieldAtLocation returns wrong values in open
                // spaces in
                // complex managers, so we override it
                public int getFieldAtLocation(int x, int y) {
                    XYRect rect = new XYRect();
                    int index = getFieldCount() - 1;
                    while (index >= 0) {
                        getField(index).getExtent(rect);
                        if (rect.contains(x, y))
                            break;
                        --index;
                    }
                    return index;
                }
            };
    

    While in the list key of field works. If I touch the buttons in the title bar, it does not. But if the keys become focus, this case they work.

    So I am in dilemma, what exactly the problem. Can someone please help.

    For me, there's a code unepxected in your touchEvent() - getFieldAtLocation().  If you want released supporess presses of field, I suggest you use code like this:

    protected boolean touchEvent (TouchEvent message) {}

    int x = message.getX (1);
    int y = message.getY (1);
    If (x < 0="" ||="" y=""> < 0="" ||="" x=""> getExtent () .width: y > getExtent () .height) {}
    Outside the scope
    Returns false;
    }

  • I want to change the blackberry listfield deafault accent color

    Hello

    I want to change the accent color of blackberry deafault (blue) of listfield, here is the code sample, code works fine, I want just to customize the color of the focus of the list... Please suggest me...

    package Meidcare;

    to import java.util.Enumeration;
    import java.util.Vector;

    Import net.rim.device.api.collection.util.SortedReadableList;
    Import net.rim.device.api.system.Bitmap;
    Import net.rim.device.api.system.Display;
    Import net.rim.device.api.ui.Color;
    Import net.rim.device.api.ui.DrawStyle;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.component.KeywordFilterField;
    Import net.rim.device.api.ui.component.KeywordProvider;
    Import net.rim.device.api.ui.component.ListField;
    Import net.rim.device.api.ui.component.ListFieldCallback;
    Import net.rim.device.api.ui.container.MainScreen;
    Import net.rim.device.api.ui.decor.BackgroundFactory;
    Import net.rim.device.api.util.Comparator;
    Import net.rim.device.api.util.StringUtilities;

    class SearchFieldDemoScreen extends screen
    {
    Vector drugs_list = new Vector();
    Image bitmap buttonleft, buttonright;
    CountryList _countryList;
    KeywordFilterField _keywordFilterField;
    int mHColor = - 1;

    public SearchFieldDemoScreen (vector drugs_list) {}
    This.drugs_list = drugs_list;
    this.getMainManager () .setBackground (BackgroundFactory.createSolidBackground (0xC2C2C2));

    buttonLeft = bitmap.getBitmapResource ("medical_pills.png");
    buttonRight = bitmap.getBitmapResource ("white_aero.png");

    _countryList = new CountryList();
    _keywordFilterField = new KeywordFilterField();

    Enumeration XmlDiffOperation = drugs_list.elements ();
    While (enumumeration.hasMoreElements ()) {}
    _countryList.addElement (new Country (enumumeration.nextElement (m:System.NET.SocketAddress.ToString (())));

    }

    try {}
    setTitle (_keywordFilterField.getKeywordField ());

    _keywordFilterField.setLabel("Find:");
    _keywordFilterField.setSourceList (_countryList, new Country.MyProvider ());
    _keywordFilterField.setCallback (new MyListFieldCallback());

    _keywordFilterField.SetFocus ();

    Add (_keywordFilterField);

    }
    catch (Exception e) {}
    System.out.println ("Exception in keyword filter field =" + e);
    }
    }

    class MyListFieldCallback implements {ListFieldCallback}

    {public drawListRow Sub (ListField listField, Graphics g, int index, int y, int width)}
    Object obj = ((KeywordFilterField) listField) .getElementAt (index);
    g.setColor (Color.BLACK);

    If (obj! = null & obj instanceof country) {}
    Point country = (country) obj;
    g.drawText (item.toString (), 20, y, DrawStyle.ELLIPSIS |) DrawStyle.HCENTER);
    g.drawLine (0, y-9, width, y-9);
    g.setColor (Color.WHITE);
    g.fillRect (0, y-9, width, 3); for 3-pixel thick seprater "line".
    g.setColor (Color.BLACK);

    } else if(index == 0) {}
    g.drawText ("* void *", 0, y);
    }

    }

    protected void drawFocus (Graphics graphics, boolean on) {}
    graphics.setColor (Color.RED);
    Paint (Graphics);
    }

    public Object get (ListField list, int index) {}
    Return drugs_list.elementAt (index);
    }

    public int getPreferredWidth (ListField list) {}
    Return Display.getWidth ();
    }

    public int indexOfList (String prefix, int start, ListField list) {}
    return 0;
    }
    }

    class CountryList extends SortedReadableList
    {
    Vector drugs_list = new Vector();

    public CountryList()
    {
    Super (new Country.CountryListComparator ());
    }

    Sub addElement (Object item)
    {
    try {}
    System.out.println ("Ankur");
    SearchFieldDemoScreen.ls2 = new ListStyleButtonSet();
    ((Field)) SearchFieldDemoScreen.ls2.add element;
    doAdd (element);
    }
    catch (Exception e) {}
    System.out.println ("Exception in Add item =" + e);
    }
    }

    }
    }

    class country
    {
    private String _countryName;

    public country (String countryName)
    {
    _countryName = countryName;
    }

    public String ToString)
    {
    Return _countryName;
    }

    public static class MyProvider implements {KeywordProvider}
    public String [] getKeywords (Object obj) {}
    Point country = (country) obj;
    return new String [] {item._countryName};
    System.out.println ("called MyProvider");
    Return StringUtilities.stringToWords (obj.toString ());
    }
    }

    public static class CountryListComparator implements comparator
    {
    public int compare (Object o1, object o2)
    {
    System.out.println ("CountryListComparator called in method compares");
    If (o1 == null | o2 == null)
    throw new IllegalArgumentException ("can't compare countries null");
    Return o1.toString () .compareTo (o2.toString ());
    }
    }
    }

    Thanks in advance...

    Oky I solved the problem...

    using the...

    {if (g.isDrawingStyleSet (Graphics.DRAWSTYLE_FOCUS))}

    change the accent color
    g.setBackgroundColor (0xDCDCDC);
    g.Clear ();
    draw text
    g.setFont (Resize.getSecondFont ());
    g.setColor (Color.BLACK);
    g.drawText (item.toString (), 20, y, DrawStyle.ELLIPSIS |) DrawStyle.HCENTER);
    }

    inside the drawListRow...

    Thank you all...

    ----------------------------------------------

    Press on as if you like it...

  • How to use the Thread in infinite ListField

    This is my code of listfield .
    
    package mypackage;
    
    import net.rim.device.api.command.CommandHandler;
    import net.rim.device.api.command.ReadOnlyCommandMetadata;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.SeparatorField;
    import net.rim.device.api.ui.component.table.SimpleList;
    import net.rim.device.api.ui.container.MainScreen;
    
    public class SimpleListDemo extends UiApplication {
        public static void main(String[] args) {
            SimpleListDemo theApp = new SimpleListDemo();
            theApp.enterEventDispatcher();
        }
    
        public SimpleListDemo() {
            pushScreen(new SimpleListScreen());
        }
    
        class SimpleListScreen extends MainScreen {
            private SimpleList listField;
    
            public SimpleListScreen() {
                super(Manager.NO_VERTICAL_SCROLL);
                setTitle("Simple List Demo");
                add(new LabelField("Blackberry Team", LabelField.FIELD_HCENTER));
                add(new SeparatorField());
                Manager mainManager = getMainManager();
                mainManager.setMargin(0, 0, 0, 50);
    
                listField = new SimpleList(mainManager);
    

    Thread th = new Thread()
    {

    public void run()
    {
    Try
    {
    listField.add ("Mr.Sushil");
    Thread.Sleep (1000);
    listField.add ("Mr.Anantha");
    Thread.Sleep (1000);
    listField.add ("Mr.Himanshu");
    }

    catch (System.Exception e)
    {
    }

    UiApplication.getUiApplication () .invokeLater (new Runnable()
    {
    public void run()
    {
    }});
    }};
    Th.Start ();

              listField.setCommand(new CommandHandler() {
    
                    public void execute(ReadOnlyCommandMetadata metadata,
                            Object context) {
    
                        if (listField.getFocusRow() == 0) {
                            UiApplication.getUiApplication().pushScreen(new P());
                        }
    
                    }
                }, null, null);
    
            }
    
        }
    
    }
    

    found the solution.

  • Click on the button to see the ListField

    Hi all
    Please help... I don't know what the problem
    I have two problems.
    I have the screen where BasicEditField and ButtonField... If I click Show me so ListField.

    Here is my source code...

    package com.screen;
    
    import java.util.Vector;
    import com.stepan.kutaj.bbmsearch.util.CustomListField;
    import com.stepan.kutaj.bbmsearch.util.ListRander;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.MenuItem;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.XYEdges;
    import net.rim.device.api.ui.component.BasicEditField;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    import net.rim.device.api.ui.decor.BorderFactory;
    
    public class Test extends MainScreen
    {
        private BasicEditField enterSearch;
        private ButtonField btnSearch;
        private String txtMenuAbout = "About";
        private Vector info = new Vector();
        private CustomListField myListView;
        private String Name;
        private Bitmap displayPicture = Bitmap.getBitmapResource("rounded.png");;
    
        public Test()
        {
            super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
    
            addMenuItem(_viewAboutMenu);
    
            this.getMainManager().setBackground(BackgroundFactory.createSolidBackground(0x00e5e5e5));
    
            Bitmap borderBitmap = Bitmap.getBitmapResource("rounded.png");
    
            VerticalFieldManager m = new VerticalFieldManager(MainScreen.NO_VERTICAL_SCROLL);
            m.setBorder(BorderFactory.createBitmapBorder(new XYEdges(12,12,12,12), borderBitmap));
    
            HorizontalFieldManager h = new HorizontalFieldManager(MainScreen.NO_VERTICAL_SCROLL);
    
            enterSearch = new BasicEditField("Search : ", "");
            btnSearch = new ButtonField("Search");
            btnSearch.setChangeListener(buttonListener);
            h.add(enterSearch);
    
            m.add(h);
            add(m);
            add(btnSearch);
    
        }
    
        public boolean onClose() {
            System.exit(0);
            return true;
        }
    
        private MenuItem _viewAboutMenu = new MenuItem(txtMenuAbout, 10, 20)
        {
           public void run()
           {
               UiApplication.getUiApplication().pushScreen(new AboutScreen());
           }
        };
    
        FieldChangeListener buttonListener = new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                if (field == btnSearch)
                {
                    Bitmap borderBitmap = Bitmap.getBitmapResource("rounded.png");
                    VerticalFieldManager s = new VerticalFieldManager(MainScreen.NO_VERTICAL_SCROLL);
                    s.setBorder(BorderFactory.createBitmapBorder(new XYEdges(12,12,12,12), borderBitmap));
    
                        for(int in = 0; in < 4; in++)
                        {
                            Name = "Name" + in;
    
                            String listTitle = Name;
                            String listDesc = "Description: ";
                            String listDesc2 = "Desc: ";
    
                            info.addElement(new ListRander(displayPicture, listTitle, listDesc, listDesc2));
                        }
    
                    myListView = new CustomListField(info)
                    {
                        protected boolean trackwheelClick (int status, int time)
                        {
                            Dialog.alert(" Selected :" + Name);
                            return super.trackwheelClick(status, time);
                        }
                    };
    
                    s.add(myListView);
                    add(s);
                }
            }
        };
    }
    

    and my problem is when I click on the button that show me ListField and context menu... and I do not know how to disable the context menu open...

    second problem is:
    in this list I generated 4 rows with unique name

    for(int in = 0; in < 4; in++)
    {
    Name = "Name" + in;
    
    String listTitle = Name;
    String listDesc = "Description: ";
    String listDesc2 = "Desc: ";
    
    info.addElement(new ListRander(displayPicture, listTitle, listDesc, listDesc2));
    }
    

    and I want to click on line, so I have to show for this specific line name...

    myListView = new CustomListField(info)
    {
        protected boolean trackwheelClick (int status, int time)
        {
           Dialog.alert(" Selected :" + Name);
           return super.trackwheelClick(status, time);
        }
    };
    

    and I have problem of course that shows me all name lines generated only modified (for example name03).

    can you help me please?

    Thank you

    Stepan

    (1) change

    btnSearch = new ButtonField ("Search");

    TO

    btnSearch = new ButtonField ("Search", ButtonField.CONSUME_CLICK);

    (2) I would have thought that you want something like

    protected boolean trackwheelClick (int status, int time)
    {
    ListRander selectedLine = (ListRander0 (this.getSekectedIndex ()) info.elementAt;

    String name = selectedLine.getName ();

    Dialog.Alert ("Selected:" + name);
    Return super.trackwheelClick (status, time);
    }

  • Help me to solve this problem in listfield

    How to add a space between two listfied. ?

    How to do a listfield to another by using the alt key?

    package com.black.applicationloader;

    import java.util.Vector;

    Import net.rim.device.api.system.Display;
    Import net.rim.device.api.ui.Color;
    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.XYRect;
    Import net.rim.device.api.ui.component.ListField;
    Import net.rim.device.api.ui.component.ListFieldCallback;
    Import net.rim.device.api.ui.container.VerticalFieldManager;

    import com.black.blackinterface.BlackInterface;
    import com.black.common.BaseScreen;
    import com.black.components.CustomEditField;
    import com.black.utility.Utilities;

    SerializableAttribute public class BlackSecondScreen extends BaseScreen implements BlackInterface, ListFieldCallback {}
    Private VerticalFieldManager listFieldManager;
    Private VerticalFieldManager listFieldManager_2;
    private static final String [] _elements is {"First element" "Second element", "Third element", 'Fourth element', 'Fifth element'};.
    private vector _listElements = new Vector (_elements.length, 1);
    columnWidth int = Display.getWidth () / 4;
    Private boolean hasFocus; = false
    Private CustomEditField userEditField;
    ListField colourList_1;
    ListField colourList_2;

    {BlackSecondScreen()}

    colourList_1 = new ListField() {}

    protected void drawFocus (Graphics graphics, boolean on) {}
    XYRect rect = new XYRect();
    graphics.setGlobalAlpha (200);
    getFocusRect (rect);
    drawHighlightRegion (graphics, HIGHLIGHT_FOCUS, true, rect.x, rect.y, rect.width, rect.height);
    }

    {} public void onFocus (int direction)
    hasFocus = true;
    super.onFocus (branch);
    }

    Called when a field loses focus.
    public void onUnfocus() {}
    hasFocus = false;
    super.onUnfocus ();
    Invalidate();
    }

    public int moveFocus (amount int, int status, time int) {}
    Invalidate (getSelectedIndex ());
    Return super.moveFocus (amount, status, time);
    }
    };

    colourList_1.setCallback (this);
    int elemWidth = _elements.length;
    for (int count = 0; count)< elementlength;="">
    {
    colourList_1.insert (count);
    This.Insert (_elements [count], count);
    }

    colourList_2 = new ListField() {}

    protected void drawFocus (Graphics graphics, boolean on) {}
    XYRect rect = new XYRect();
    graphics.setGlobalAlpha (200);
    getFocusRect (rect);
    drawHighlightRegion (graphics, HIGHLIGHT_FOCUS, true, rect.x, rect.y, rect.width, rect.height);
    }

    {} public void onFocus (int direction)
    hasFocus = true;
    super.onFocus (branch);
    }

    Called when a field loses focus.
    public void onUnfocus() {}
    hasFocus = false;
    super.onUnfocus ();
    Invalidate();
    }

    public int moveFocus (amount int, int status, time int) {}
    Invalidate (getSelectedIndex ());
    Return super.moveFocus (amount, status, time);
    }
    };

    colourList_2.setCallback (this);

    for (int count = 0; count)< elementlength;="">
    {
    colourList_2.insert (count);
    This.Insert (_elements [count], count);
    }

    Add (colourList);
    createComponents();
    layoutComponents();

    }

    public void createComponents() {}

    listFieldManager = new VerticalFieldManager (Manager.VERTICAL_SCROLL |) Manager.HORIZONTAL_SCROLL) {}
    protected void sublayout (int maxWidth, maxHeight int) {}
    Super.sublayout (maxWidth, 2 * colourList_1.getRowHeight ());
    setExtent (maxWidth, 2 * colourList_1.getRowHeight ());

    };

    };

    listFieldManager_2 = new VerticalFieldManager (Manager.VERTICAL_SCROLL |) Manager.HORIZONTAL_SCROLL) {}
    protected void sublayout (int maxWidth, maxHeight int) {}
    Super.sublayout (maxWidth, 2 * colourList_2.getRowHeight ());
    setExtent (maxWidth, 2 * colourList_2.getRowHeight ());

    };

    };

    userEditField = new CustomEditField (Utilities.getAdjustedWidth (150))
    Utilities.getAdjustWidth (2), Manager.NO_HORIZONTAL_SCROLL
    // | (Manager.VERTICAL_SCROLL, true);

    }

    public void layoutComponents() {}
    TODO self-generating method stub
    listFieldManager.add (colourList_1);

    listFieldManager_2.add (colourList_2);
    Add (listFieldManager);
    Add (listFieldManager_2);

    }

    public void initializeListeners() {}
    TODO self-generating method stub

    }

    public void setComponentsXYMargins() {}
    TODO self-generating method stub

    }

    ' Public Sub drawListRow (ListField listField, graphics graphics, int index,
    int y, int width) {}
    int curSelected;
    If (hasFocus) {}
    curSelected = listField.getSelectedIndex ();
    } else {}
    curSelected = - 1;
    }
    If (index %2 == 0) {}
    graphics.setColor (Color.PERU);
    graphics.fillRect (0, y, width, listField.getRowHeight ());
    } else {}
    graphics.setColor (Color.WHEAT);
    graphics.fillRect (0, y, width, listField.getRowHeight ());
    }
    graphics.fillRect (0,0,width,y);

    int xPos = 0; int ypos = 0;
    graphics.setFont (Font.getDefault ()); / / Please set a value of fonts
    It is the first text of the column
    graphics.setColor (Color.BLACK);
    graphics.drawText("column1"+index,xpos,y);
    XPos += columnWidth;

    graphics.setColor (Color.RED);
    graphics.drawText("column2",xpos,y);

    XPos += columnWidth;
    graphics.drawText("column3",xpos,y);

    XPos += columnWidth;

    graphics.drawText("column4",xpos,y);

    }

    public Object get (ListField listField, int index) {}
    TODO self-generating method stub
    Return _listElements.elementAt (index);
    }

    public int getPreferredWidth (ListField listField) {}
    TODO self-generating method stub
    Return Graphics.getScreenWidth ();
    }

    public int indexOfList (String prefix, int start, ListField listField) {}
    TODO self-generating method stub
    Return _listElements.indexOf (prefix, start);
    }

    public final void insert (String toInsert, int index)
    {
    _listElements.insertElementAt (toInsert, index);
    }

    public void erase()
    {
    _listElements.removeAllElements ();
    }

    }

    Hello

    Not able to understant it please explain...

  • How to display the scroll bar on the listField

    I use the following code to add a listField to VerticalManager, but he couldn't display a vertical scroll bar.

    Thanks for any help.

    Michael

    SerializableAttribute public class ContactsListField extends VerticalFieldManager
    {

    .......

    public ContactsListField (int width, int height, string keyword)
    {
    Super(Manager.NO_VERTICAL_SCROLL |) Manager.FIELD_HCENTER);
            
    managerWidth = width;
    managerHeight = height;
    VerticalFieldManager vor = new VerticalFieldManager(Manager.VERTICAL_SCROLL |)
    Manager.VERTICAL_SCROLLBAR | Manager.FIELD_HCENTER | Manager.FIELD_VCENTER);
            
    listField = new ListField(0,ListField.FOCUSABLE)
    {
    public void paint (Graphics g)
    {
    getManager () .invalidate ();
    Super.Paint (g);
    }
    };
            
    listCallback = new ListCallback();
    listField.setCallback (listCallback);
            
    contacts = getData();
    If (contacts! = null)
    filterKeyword (keyword);
                        
    VFM. Add (ListField);
    Add (VFM);
    }

    Hmm... nothing extraordinary.  One might want to draw focus in the ListField by defining a suitable background and foreground colors, but still - there is nothing that would prevent the drawing of the ScrollBar by the Manager.  Of course, Manager.FIELD_VCENTER is not used in the optimization of resources, and I suspect that FIELD_HCENTER will be useless too (I think ListField uses all of the default width).  You can delete these two style bits.

    One thing to check - what can you add that ContactListField to?  If it's a screen or a derived class, you must use NO_VERTICAL_SCROLL in the constructor.  In this way, you will ensure that is vfm that manages the painting "scrollbar".

  • How to get the element selected listfield and goto next page?

    Assalaamualikum

    I try parsing the XML from a url and show in listfield.

    problem:

    How to get the selected item and passing the variable and than goto next page?

    my code:

    package parsepack;

    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Vector;

    Import javax.microedition.io.Connector;
    Import javax.microedition.io.StreamConnection;

    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.FieldChangeListener;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.Manager;
    Import net.rim.device.api.ui.UiApplication;
    Import net.rim.device.api.ui.component.ListField;
    Import net.rim.device.api.ui.component.ListFieldCallback;
    Import net.rim.device.api.ui.container.MainScreen;
    Import net.rim.device.api.ui.container.VerticalFieldManager;
    Import net.rim.device.api.xml.parsers.DocumentBuilder;
    Import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

    to import org.W3C.DOM.document;
    Import org.w3c.dom.Node;
    Import org.w3c.dom.NodeList;

    extends xmlparsing public class UiApplication implements ListFieldCallback, FieldChangeListener
    {

    Public Shared Sub main (String [] args)
    {
    xmlparsing app = new xmlparsing();
    app.enterEventDispatcher ();
    }

    public long mycolor;
    Connection _connectionthread;
    private static ListField _list;
    private static Vector listElements is new Vector();.
    public display display = new MainScreen();
    MainManager VerticalFieldManager;
    VerticalFieldManager subManager;

    public xmlparsing()
    {
    Super();
    pushScreen (screen);

    final Bitmap Imagearriereplan = Bitmap.getBitmapResource ("blackbackground.png");

    mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL |) Manager.NO_VERTICAL_SCROLLBAR)
    {

    public void paint (Graphics graphics)
    {
    graphics.drawBitmap (0, 0, Display.getWidth (), Display.getHeight (), Imagearriereplan, 0, 0);

    Super.Paint (Graphics);
    }

    };

    subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL |) Manager.VERTICAL_SCROLLBAR)
    {
    protected void sublayout (int maxWidth, maxHeight int)
    {
    int displayWidth = Display.getWidth ();
    int displayHeight = Display.getHeight ();

    Super.sublayout (displayWidth, displayHeight);
    setExtent (displayWidth, displayHeight);
    }
    };

    Screen.Add (mainManager);

    _list = new ListField()

    {

    public void paint (Graphics graphics)

    {
    graphics.setColor ((int) mycolor);
    Super.Paint (Graphics);

    }

    };
    myColor = 0x00FFFFFF;
    _list. Invalidate();
    _list.setEmptyString ("* only supplies not available *", DrawStyle.HCENTER "");
    _list.setRowHeight (50);
    _list.setCallback (this);
    mainManager.add (subManager);
    listElements.removeAllElements ();
    _connectionthread = New Connection();
    _connectionthread. Start();
    }

    protected boolean navigationClick (int status, int time)
    {
    Try
    {
    Here, go to another screen if you need.

    }
    catch (System.Exception e)
    {
    System.out.println ("Exception:-: navigationClick()" + try ());
    }
    Returns true;
    }

    private class login extends thread
    {
    Public connection()
    {
    Super();
    }

    public void run() {}
    Doc document;
    StreamConnection conn = null;
    InputStream is = null;
    try {}

    Conn = Connector.open (StreamConnection) ("http://ec2-54-248-241-248.ap-northeast-1.compute.amazonaws.com/koperasi-akr-trial/cgi-bin/gw-pinjama...

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance ();
    docBuilderFactory.setIgnoringElementContentWhitespace (true);
    docBuilderFactory.setCoalescing (true);
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder ();
    docBuilder.isValidating ();
    is = conn.openInputStream ();
    doc = docBuilder.parse (is);
    doc.getDocumentElement () .normalize ();
    List of NodeList = doc.getElementsByTagName ("ID");
    for (int i = 0; i)< list.getlength();="" i++)="">
    Node node = list.item (i) .getFirstChild ();
    listElements.addElement (textNode.getNodeValue ());
    }
    } catch (Exception e) {}
    System.out.println (try ());
    } {Finally
    If (is! = null) {}
    try {is.close ();
    } catch (IOException ignored) {}
    } If (conn! = null) {}
    Try {conn.close () ;}
    catch (IOException ignored) {}
    }} UiApplication.getUiApplication () .invokeLater (new Runnable() {}
    public void run() {}
    _list. SetSize (listElements.Size ());
    subManager.add (_list);
    Screen.Invalidate ();
    }
    });
    }

    }

    ' public void drawListRow (list ListField, Graphics g, int index, int y, int w)
    {
    Your string = (String) listElements.elementAt (index);
    int yPos = 0 + y;
    g.drawLine (0, yPos, w, yPos);
    g.drawText (, 5, 15 + y, 0, w);
    }

    public {get {Object (ListField list, int index)
    {
    Return listElements.elementAt (index);
    }
    public int indexOfList (String prefix, ListField list, int, string)
    {
    Return listElements.indexOf (prefix, string);
    }
    public int getPreferredWidth (ListField list)
    {
    Return Display.getWidth ();
    }
    public final void insert (String toInsert, int index) {}
    listElements.addElement (toInsert);
    }

    ' Public Sub fieldChanged (field field, int context) {}

    }
    }

    Thank you.

    I told you that replace the navigationclick() method where initialize you your listfield

    as I think that changing your code and then answer me

    _list = new ListField()
    {
    protected boolean navigationClick(int status, int time)
    {
      Dialog.inform("hi");
      return true;
    }
    
    public void paint(Graphics graphics)
    {
    graphics.setColor((int) mycolor);
    super.paint(graphics);
    }
    };
    
  • Problem with image extract the content and the tile at the same time show on ListField

    My application is Application News get JSON webservice to appear on ListField.

    On each line in the list, it will show you the image thumbnail, title and Teaser as below.

    _______________________________________

    |                |                       Title

    |   Thumb  |_______________________________

    |_______  |                       Teaser

    First of all, I have to get JSON that contains the url of the thumbnail image, title and Teaser.


    I managed to view the title and Teaser, but the thumbnail is not. When I Fetch image with the url of the thumbnail image, it returns only bitmap = null for me.

    My method is first call httpdispatcher to get the thumbnail image, title and Teaser and then wait and call another httpdispatcher to retrieve the url of the image thumbnail, then added to listfield.

    Here is my code

    Class helloScreen{
    
    public void requestSucceeded(byte[] result, String contentType)   {      if (contentType.equals("image/png") ||        contentType.equals("image/jpeg") || contentType.equals("image/gif") ||contentType.equals("image/jpg")) {         bitmap_temp = Bitmap.createBitmapFromBytes(result, 0, result.length, 1);                     synchronized (UiApplication.getEventLock()) {
    
                   }         }         else if (contentType.startsWith("text/")) {
    
                  strResult = new String(result);
    
                 try {                     ja = new JSONArray(strResult);
    
                  } catch (JSONException e) {                   // TODO Auto-generated catch block                    e.printStackTrace();              }
    
               synchronized (UiApplication.getEventLock()) {
                                  int temp_int_next=0;
                    try {
                        callback.erase();
                         for(int x=0;x<10;x++){
    
                             j = (JSONObject) ja.get(x);
    
     String get_htmlOff_first = j.get("teaser").toString().substring(j.get("teaser").toString().indexOf(">")+1);
     final String thumb = replace(j.get("thumb").toString(),"files/","http://www.eng.chula.ac.th/files/");
    
                                    UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    
                                    public void run() {
    
                           getImageURL(thumb); 
    
                                 }});                      
    
    callback.insert(j.get("title")+" ", ""+get_htmlOff_first.trim(), bitmap_temp , temp_int_next , "Event");                      temp_int_next++;
    
                      }
    
                       } catch (JSONException e) {                  // TODO Auto-generated catch block                    e.printStackTrace();              }               
    
                }         }         else {            synchronized (UiApplication.getEventLock()) {         Dialog.alert("Unknown content type: " + contentType);         }         }
    
    
    
    public void getImageURL(String url) {                HttpRequestDispatcher dispatcher2 = new HttpRequestDispatcher(url,                "GET", this);    }
    

    }

    httpRequest, class Dispatcher is used to get the data from the url

    public HttpRequestDispatcher(String url, String method, helloScreen screen)
    {
    this.url = url;
    this.method = method;
    this.screen = screen;
    
    }
    
    public String getType(){
    
        return type;
    
    }
    
    public void run() {
        try {
    
            if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
           {
                connection = (HttpConnection)Connector.open(url+";interface=wifi");
         }else{
    
            String uid = getWap2Uid();
            connection = (HttpConnection)Connector.open(url+";deviceside=true;ConnectionUID=" + uid);
    
            }
    
        connection.setRequestMethod(method);
    
        connection.setRequestProperty("Accept","text/html, image/jpg, image/jpeg, image/,image/gif");
    
        int responseCode = connection.getResponseCode();
        if (responseCode != HttpConnection.HTTP_OK) {
        screen.requestFailed("Unexpected response code: " + responseCode);
        connection.close();
        return;
        }
        final String contentType = connection.getHeaderField("Content-type");
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream responseData = connection.openInputStream();
        byte[] buffer = new byte[10000];
        int bytesRead = responseData.read(buffer);
        while(bytesRead > 0) {
        baos.write(buffer, 0, bytesRead);
        bytesRead = responseData.read(buffer);
        }
        baos.close();
        connection.close();
    
                  UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    
                        public void run() {
    
                            screen.requestSucceeded(baos.toByteArray(), contentType);
    
                        }
    
                        });
    
        } catch (IOException ex) {
        screen.requestFailed(ex.toString());
        }
    }
    

    The point here is that I have JSON and get the url of the thumbnail to fetch before add to listfield. The image should be ready in bitmap_temp but it still get null.

    UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    
                                   public void run() {
    
                           getImageURL(thumb); 
    
                                 }});
    
    public void getImageURL(String url) {                HttpRequestDispatcher dispatcher2 = new HttpRequestDispatcher(url,                "GET", this);    }
    
    callback.insert(j.get("title")+" ", ""+get_htmlOff_first.trim(), bitmap_temp , temp_int_next , "Event");
    

    All day trying to fix it but no success, so I need help from you guys.

    Thank you

    "Is it possible to leave only 1 thread completely pick 10 pictures.

    Yes and this is how I would recommend that do you it this way.  So have a Thread that you give a list of things to do and let it work through each.

  • ListField line personalized with text and images

    Hello

    I use the example of complex files provided at this URL as a basis for my application. I want to do is get data feed from a Web site and post it in a ListField. Each row in the field has a picture and associated text.

    I made the following changes in my implementation of the application in the example

    1. create a normal ListField instead of a subclass of ListField

    2 getting data from the stream and fill a vector with the necessary information

    3. implementation of the ListFieldCallback.

    In the drawListRow of the callback method, I create a TableRowManager object and pass the data for that particular line. Using these data, I create fields and adding them to the TableRowManager. Then by the drawRow of the TableRowManager method, I call sublayout() and specifying the x, y, width, height for each field in the TableRowManager.

    Now, when you debug the application, I see that the drawListRow method is called whenever I move around the list or when the ListField is first added to its parent. But none of the fields or lines are displayed.

    DrawRow even is called whenever drawListRow. But the lines are never displayed. I just get a white screen. Tried to remove all fields and keep a single LabelField, but even that is not displayed.

    Here's the code, if this is useful

    Class TableRowManager

    private class TableRowManager extends Manager
        {
            int _index;
    
            TableRowManager(String myTxt, String msg, String imageUrl, int index)
            {
                super(0);
                BitmapField imgField = new WebBitmapField(imageUrl);
                add(imgField);
    
                LabelField personLabel = new LabelField(myTxt, DrawStyle.ELLIPSIS);
                add (personLabel);
    
                LabelField itemLabel = new LabelField(msg, DrawStyle.ELLIPSIS);
                add(itemLabel);
    
                _index = index;
            }
            public void drawRow(Graphics g, int x, int y, int width, int height)
            {
                layout(width, height);
                setPosition(x, y);
                g.pushRegion(getExtent());
                g.popContext();
            }
            protected void sublayout(int width, int height)
            {
                Field currField1 = getField(0);
                layoutChild(currField1, getPreferredWidth(), getPreferredHeight());
                setPositionChild(currField1,0,0);
                Field currField2 = getField(1);
                layoutChild(currField2, (int) Field.USE_ALL_WIDTH, getPreferredHeight());
    
                setPositionChild(currField2,40,80);
    
                Field currField3 = getField(2);
                layoutChild(currField3, (int) Field.USE_ALL_WIDTH, getPreferredHeight());
                setPositionChild(currField3,40,120);
    
                setExtent(getPreferredWidth(), getPreferredHeight());
            }
            public int getPreferredWidth()
            {
                return Display.getWidth();
            }
            public int getPreferredHeight()
            {
                return 150;
                //return height of row
            }
        }
    

    the callback method drawListRow

    public void drawListRow(ListField list, Graphics g, int index, int y, int w)
        {
            String text = (String)listElements.elementAt(index);
            String str1 = text.substring(0,text.indexOf("-"));
            String str2 = text.substring(text.indexOf("-")+2);
            String imageName = image[index];
           String url = "http://myURL/"+imageName;
           TableRowManager rowManager = new TableRowManager(str1,str2,url, index);
            rowManager.drawRow(g, 0, y, w, list.getRowHeight());
        }
    

    Can someone please help me with this. The format of what I'm looking for is something like this

    ------------

    | image |  LabelField1

    |           |  LabelField2

    -------------

    Thank you.

    What I usually do with the listField is myself to draw the bitmap and text, something like the following:

    ' public void drawListRow (list ListField, Graphics g, int index, int y, int w)
    {
    String text = (String) listElements.elementAt (index);
    String str1 = text.substring (0, text.indexOf("-"));
    String str2 = text.substring (text.indexOf("-") + 2);
    String imageName = image [index];

    Z.i. bitmap = / * get the bitmap * / (better preparation before coming here, for performance)

    int xPos = LEFT_OFFSET;
    int ypos = TOP_OFFSET + y;
    int w = bitm.getWidth ();
    int h = bitm.getHeight ();
    fontHeight int = this.getFont () .getHeight ();

    g.drawBitmap (PosX, Posy, w, h, z.i., 0, 0);

    PosX = w + SOME_OFFSET

    graphics.drawText (str1, xpos, ypos);
    YPos += fontHeight;

    graphics.drawText (str2, xpos, ypos);

    }

    It worked for me all the time.

    Of course, I don't want to say that do you it this way, but I'm just give another alternative that works.

    Rab

  • The remote XML parsing and ListField implementation

    I use Blackberry 9800 Simulator, JRE 6.0.0

    Hello

    I have a remote XML I want to analyze, but for some reason, my ListField shows only 1 row. I tried debugging and saw the number of attributes my vector, which is significantly greater than 1.

    Here is my code: http://pastebin.com/zRDW2xfn

    I'm doing something wrong?

    In addition, in the ListFieldCallback, the drawListRow index does not increment...

    Hey there,

    I found the problem, if you print the exception, you will see what is wrong. Basically, you dodnt have access to the UI within this thread.

    I changed the class connectionthread for you below.

    private class Connection extends Thread{
    
            public String title;
            public int i=0;
    
            public Connection(){
                super();
            }
    
            public void run(){
                // define variables later used for parsing
                Document doc;
                StreamConnection conn;
                try{
                    conn = (StreamConnection)Connector.open("http://tpae.me/events.xml;deviceside=true");
                    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                    docBuilder.isValidating();
                    doc = docBuilder.parse(conn.openInputStream());
                    doc.getDocumentElement().normalize();
                    NodeList list = doc.getElementsByTagName("Event");
    
                    for (i=0;i
    

    Note: the fix is not optimal, but his show you how it should be done.

    Please let me know if you still have problems or questions.

  • ListField.drawListRow only draws a line in the first row, all the lines.

    I'm close. ListField.drawListRow is called for every row without problem, but the two graphics.drawLine only are displayed (shot) in the first row at the point of coordinates noted.

    I thought that each line would get the two drawn drawLines?

    Graphics.Clear is called correctly (as a test only - I have commented out them as well, but not changes).

    How can I get the two Graphics.drawLine at the bottom of the method called for each line, correctly?

    public void drawListRow(ListField listField, Graphics graphics, int index,
            int y, int width) {
        Logger.debug("CoffeeStoreContent [drawListRow] y: " + y + " width: " + width);
        /*
         * Top Margin
         */
        y += appGraphics.calcHiRes(6);
    
        int[] colors = appGraphics.getColorPalette(sportTitle);
    
        /*
         * Get the current CoffeeStore object.
         */
        CoffeeStore currentRow = (CoffeeStore) get(listField, index);
    
        StringBuffer subline = new StringBuffer(currentRow.getSource());
        subline.append(Characters.SPACE);
        subline.append("|");
        subline.append(Characters.SPACE);
        subline.append(currentRow.getDateAgo());
    
        int HiX = 43;
    
        if (graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
            graphics.clear();
            graphics.setColor(AppGraphics.YELLOW_HIGHLIGHT);
            graphics.fillRect(0, (index * listField.getRowHeight()),
                    listField.getWidth(), listField.getRowHeight());
    
            graphics.setFont(font);
            graphics.setColor(Color.BLACK);
            graphics.drawText(currentRow.getLinkText(), HiX, y, 0, width);
    
            graphics.setColor(AppGraphics.TEIGHT);
            graphics.drawText(subline.toString(), HiX, (y
                    + graphics.getFont().getHeight() + 2), 0, width);
        } else {
            graphics.clear();
            graphics.setColor(colors[0]);
            graphics.fillRect(0, (index * listField.getRowHeight()),
                    listField.getWidth(), listField.getRowHeight());
    
            graphics.setFont(font);
            graphics.setColor(AppGraphics.TSIX);
            graphics.drawText(currentRow.getLinkText(), HiX, y, 0, width);
    
            graphics.setColor(Color.WHITE);
            graphics.drawText(subline.toString(), HiX, (y
                    + graphics.getFont().getHeight() + 2), 0, width);
        }
    
        graphics.setColor(colors[2]);
        graphics.drawLine(0, 50, width, 50);
        graphics.setColor(colors[3]);
        graphics.drawLine(0, 51, width, 51);
    }
    

    No - only y + 50 is enough.

Maybe you are looking for