ListField color

package mypackage;
import java.util.Vector;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.DrawStyle;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;

public class SingersListField extends ListField {

      private Vector content = null;
      private ListCallback callback = null;
      private int currentPosition = 0;

      /**
        * Instantiates a new title list and populates it with the appropriate items.
        *
        * @param content The content to be loaded in the list.
        */
      public SingersListField (Vector content) {
        this.content = content;
        initCallbackListening();
       // font = this.getFont().derive(Font.BOLD, 16);
       // this.setFont(font);
        this.setRowHeight(100);    // I think this is an important point for it to work: set the height of the row outside the draw method.
        // Other possibly useful info is that the negative signal means I will multiply the font size by the number provided.
      }

      private void initCallbackListening() {
        callback = new ListCallback();
        this.setCallback(callback);
      }

      /**
        * Callback implementation to this custom list field.
        *
        * @author Alaa El-Khatib
        */
      private class ListCallback implements ListFieldCallback {

        private Bitmap image = null;
        Bitmap Arrow = Bitmap.getBitmapResource("arrow.png");
        Bitmap Arrow2 = Bitmap.getBitmapResource("arrow2.png");
        public ListCallback() {
        }
        public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
              if(index!=-1){
          currentPosition = listField.getSelectedIndex();
          int yPos = 5 + y; // initial position will consider an offset.
          int xPos = 15; // left offset, fixed for all rows in the list.
         Song temp =  (Song)content.elementAt(index);
          image=MAMClient.sizeImage(EncodedImage.createEncodedImage(temp.getAlbumCover(), 0, temp.getAlbumCover().length),110,110).getBitmap();
          graphics.drawBitmap(5, yPos, image.getWidth(), image.getHeight(), image, 0, 0);
          xPos = xPos + image.getWidth();
          if (graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))
            {
             // graphics.setColor(0x858686);
              Font font = getFont().derive(Font.BOLD, 32);
              graphics.setFont(font);
              graphics.drawText(temp.albumName,  xPos , yPos,DrawStyle.ELLIPSIS,width-(image.getWidth()+Arrow2.getWidth()+10));
              font = getFont().derive(Font.PLAIN, 32);
                 graphics.setFont(font);
              graphics.drawText(temp.singerName,  xPos , yPos+25,DrawStyle.ELLIPSIS,width-(image.getWidth()+Arrow2.getWidth()+10));
              font = getFont().derive(Font.ITALIC, 32);
                 graphics.setFont(font);
                 graphics.drawText("ALBUM - "+temp.getPrice()+" KWD",  xPos , yPos+50,DrawStyle.ELLIPSIS,width-(image.getWidth()+Arrow2.getWidth()+10));
              graphics.drawBitmap(width-Arrow2.getWidth()-5, yPos, Arrow2.getWidth(), Arrow2.getHeight(), Arrow2, 0, 0);}
            else
            {
              //graphics.setColor(0x60347A);
                Font font = getFont().derive(Font.BOLD, 32);
                 graphics.setFont(font);
              graphics.drawText(temp.albumName,  xPos , yPos,DrawStyle.ELLIPSIS,width-(image.getWidth()+Arrow.getWidth()+10));
              font = getFont().derive(Font.PLAIN, 32);
                 graphics.setFont(font);
              graphics.drawText(temp.singerName,  xPos , yPos+25,DrawStyle.ELLIPSIS,width-(image.getWidth()+Arrow2.getWidth()+10));
              font = getFont().derive(Font.ITALIC, 32);
                 graphics.setFont(font);
                 graphics.setColor(Color.GRAY);
                 graphics.drawText("ALBUM - "+temp.getPrice()+" KWD",  xPos , yPos+50,DrawStyle.ELLIPSIS,width-(image.getWidth()+Arrow2.getWidth()+10));
             graphics.drawBitmap(width-Arrow.getWidth()-5, yPos, Arrow.getWidth(), Arrow.getHeight(), Arrow, 0, 0); }
           graphics.setColor(0x60347A);
          yPos = y + listField.getRowHeight() - 1;
          graphics.drawLine(0, yPos,Display.getWidth(), yPos);
              }}

        public Object get(ListField listField, int index) {
          return content.elementAt(index);
        }

        public int getPreferredWidth(ListField listField) {
          return Display.getWidth();
        }

        public int indexOfList(ListField listField, String prefix, int start) {
          return content.indexOf(prefix, start);
        } }

      // This method returns the index of the highlighted item in the list, which will be useful somewhere in my code.
      public int getCurrentPosition() {
        return currentPosition;
      } 

      protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(0);
            //Song temp =  (Song)content.elementAt(currentPosition);
            //UiApplication.getUiApplication().pushScreen(new SingersCategory(temp.getSingerId(),temp.albumName,temp.getAlbumCover()));
            return true;
        }

      protected void drawFocus(Graphics graphics, boolean on) {
          XYRect rect = new XYRect();
          getFocusRect(rect);
          if (on) {
          graphics.setColor(Color.PURPLE);
          graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
          getCallback().drawListRow(this, graphics, getSelectedIndex(), rect.y, rect.width);
          }
      } }

As you can see I have a list, selection of the line I've highlight violet. But because the letters are black, they disappear. What advice you can offer?

On selection change text in black and white colors? If Yes can give u how?

or I make settings on the appropriate colors? and can u advice what colors?

I solved the problem with this

drawHighlightRegion (graphics, HIGHLIGHT_FOCUS, on, rect.x, rect.y, rect.width, rect.height);

Tags: BlackBerry Developers

Similar Questions

  • Try to give the other a ListField coloring line

    I want to substitute a ListField coloring online.

    I've implemented a ListField and the drawListRow ListFieldCallback, I have the following:

          public void drawListRow(ListField list, Graphics g,                                    int index, int y, int w) {           if(index % 2 != 0)          {               g.setColor(0xB2FFED);               g.fillRect(0, y, w, list.getRowHeight());               g.setColor(0x000000);               list.invalidate(index);         }                       String text = (String)listElements.elementAt(index);            g.drawText(text, 0, y, 0, w);           }
    

    It works, but he also painted the selected item with the color I put.  I want to continue to paint the selected item with the system-defined color.  I tried to add a check for list.getSelectedItem! = index, but that doesn't seem to work very well.

    Is there an example of what I want to do?

    Hi rgelb1,

    I think this KB Article How To - create a ListField color is what you're looking for, he explains how to draw some fields with color while keeping separate highlighting. I hope this helps, if not I will help you with the necessary code.

    Concerning

    André

  • 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!

  • 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...

  • Customizing the background color for an element ListField

    I spent the better half of today trying to figure out how to set the background color for when a ListField element has the focus. I tried the substitution of paint and drowFocus and can not get any color other than the default.

    Someone knows how to do this?

    Try something like that.

     public void drawListRow(ListField list, Graphics g, int index, int y, int w)
    {
        if(list.getSelectedIndex() == index)
        {
             g.setColor(0x0000FF);
             g.fillRect(0,(index*rowHight),rowWidth,rowHeight);
             g.setColor(0x000000);
        }
        g.drawText("Text", 0, y, 0, w);
    }
    

    PS: Call disabled, if the previous paint stays on the screen.

  • ListField set highlight color

    Hello!

    I make a list of items, with my own custom ListField. I use the example of TaskListField and change to my design.

    I changed the background color of the items correctly, but now I want to change the highlight color of the list item selected from blue to red. I use the drawListRow method:

    public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
            ListaTours list = (ListaTours) listField;
    
            if(list.getSelectedIndex() == index){
                System.out.println("Selected index: "+index);
                g.clear();
                g.setColor(0xFFb00000);
                g.fillRect(0,(index*this.getRowHeight()), this.getWidth(), this.getRowHeight());
            }
            else{
                g.clear();
                g.setColor(0xe8e8e8);
                g.fillRect(0,(index*this.getRowHeight()), this.getWidth(), this.getRowHeight());
            }
        }
    

    I can successfully change the selected color, but my "problem" is that the first element is always highlighted even if I didn't go. The default variable index value is 0, and makes my first item to be always highlighted. Is it possible to asigning the first value of index-1?

    I know I could just substitute the ListField object method, but if I do, my bitmap images do not show up correctly

    Thank you in advance!

    Instead of

    If (List.getSelectedIndex () == index)

    try to use

    If (g.isDrawingStyleSet (Graphics.DRAWSTYLE_FOCUS))

  • Color of the ListField always black text (on real devices)

    Hello

    I have a problem. I tried a lot of ListView and tried to change the color of the text of the items. It always works on the Simulator but on certain 9700 devices, that the text is always black.

    An example of code where the color of the text is isntead red black (also the background is not green).

    public class testscreenDraw3 extends MainScreen {
    
        testscreenStart _testscreenStart;
    
        private ListField _listField;
        VerticalFieldManager vfm;
    
        int foregroundcolor = 0;
        boolean show_foreground = false;
    
        public testscreenDraw3(testscreenStart _temp) {
            _testscreenStart = _temp;
    
            _listField = new ListField();
              ListCallBack _callback = new ListCallBack();
              _listField.setCallback(_callback);
    
              _listField.insert(0);
              _callback.insert("Testing 123", 0);
    
              _listField.insert(1);
              _callback.insert("Testing 123", 1);
    
              _listField.insert(2);
              _callback.insert("Testing 123", 2);
    
            //vfm.add(_listField);
            this.add(_listField);
    
            show_foreground = true;
            this.invalidate();
    
        }
    
          class ListCallBack implements ListFieldCallback
          {
           private Vector listElements = new Vector();
    
           public void drawListRow(ListField list, Graphics g, int index, int y, int w)
           {
            String text = (String)listElements.elementAt(index);
            //g.clear();
            g.setBackgroundColor(Color.GREEN);
            g.setColor(Color.RED);
            g.drawText(text, 0, y, 0, w);
    
           }
    
           public Object get(ListField list, int index)
           { return listElements.elementAt(index); }
    
           public int getPreferredWidth(ListField list)
           { return Display.getWidth();}
    
           public void insert(String toInsert, int index)
           { listElements.insertElementAt(toInsert, index); }
    
           public void erase()
           { listElements.removeAllElements(); }
    
              public int indexOfList(ListField listField, String prefix, int start) {
               return listElements.indexOf(listField);
              }
          }
    
        protected boolean onSavePrompt() {
            return true;
        }
    
    }
    

    Help, please! I have this problem for some time now...

    Kind regards

    Sander

    You are probably a person the theme of the unit. The theme will be 'hijack' the color of the text on certain controls.

    You might want to try to create a vacuum override:

    Protected Sub applyTheme()'

    {

    }

    .. .to defeat the theme engine.

  • How to show the ListField focus point in reverse or other color

    I saw similar comments, but not enough information to go. I'm new to b'berry and java too, this is my first application, and it comes to Notifications, storage options, the requests HTTP, XML and browser integration, there has been a steep learning curve!

    I have a ListField with a ListFieldCallback, which draws text in the list of members. When the wheel is used to select items, the background is blue but unchanged in the foreground, making almost unreadable text. I want the text to be reversed in color, or blue background (preferably) be a rectangle outline. I think that the answer lies somewhere like getCallback and focusRect, but I don't know what to do. Ideally, I would like to change the code in the callback class 'drawListRow()', but I suspect that things are not so simple!

    My code looks like (sorry I can't put much too, I wanted to know what pieces of change):

    ...
    
    final class SMobile extends UiApplication
    {
    ...
        private ListCallback myCallback;
        private ListField myList;
    
        public static void main(String[] args)
        {
    ...
                SMobile theApp = new SMobile( true);
                theApp.enterEventDispatcher();
    ...
        }
    ...
        private SMobile( boolean runmode)
        {
    ...
                myList = new ListField();
                myCallback = new ListCallback();
                myList.setCallback(myCallback);
                myCallback.erase();
    
                _mainScreen.add(myList);
    ...
                pushScreen(_mainScreen);
        }
    ...
        private static class ListEntry {
            public String s = "";
            public String t = "";
            public String f = "";
            public String st = "";
            public String m = "";
        }
    
        private static class ListCallback implements ListFieldCallback {
            private Vector listElements = new Vector();
    
            public void drawListRow(ListField list, Graphics g,
                                            int index, int y, int w) {  
    
                ListEntry _entry = (ListEntry)listElements.elementAt(index);
    
                if ( _entry.st.indexOf("U") != -1)
                {
                    g.setColor( Color.DARKRED);
                }
                else
                {
                    g.setColor( Color.DARKGREEN);
                }
    
                Font _font = g.getFont();
                int size = (_font.getHeight() ) / 2;
                _font = _font.derive(0, size, Ui.UNITS_px);
                g.setFont( _font);
                g.drawText(_entry.s.concat(", ").concat(_entry.t).concat(",").concat(_entry.st),
                            0, y+1, (int)( DrawStyle.ELLIPSIS | DrawStyle.LEFT ), w);
    
                g.setColor( Color.BLACK);
                g.drawText(_entry.f.concat(", ").concat(_entry.m),
                            10, y + _font.getHeight()-1,
                            (int)( DrawStyle.ELLIPSIS | DrawStyle.LEFT ), w);
            }
    
            public Object get(ListField list, int index) {
                return listElements.elementAt(index);
            }
            public int indexOfList(ListField list, String p, int s) {
                return -1; //Not implemented, as we have an object in the Vector, not a string
            }
            public int getPreferredWidth(ListField list) {
                return Display.getWidth();
            }
            public void insert(ListEntry toInsert, int index) {
                listElements.insertElementAt(toInsert, index);
            }
            public void erase() {
                    listElements.removeAllElements();
            }
        }
    
    ...
    }
    

    Please can someone advise?

    Thank you.

    Steve

    Thanks Mark,

    I ended up using a similar method with a twist. I drew a background rectangle slightly smaller than the list item, then the blue selection box turns into a blue outline, and colors of foreground elements are not hidden by it:

    ...
            public void drawListRow(ListField list, Graphics g,
                                            int index, int y, int w) {  
    
                ListEntry _entry = (ListEntry)listElements.elementAt(index);
    
                //Draw background rectangle to replace dk blue selection rectangle with outline only
                g.setColor( Color.WHITESMOKE); //Pale but not white
                int h = list.getRowHeight();
                g.fillRect( 2, y+2, w-4, h-4);
    ...
    

    Steve

  • ListField background color NOT COLOR FOCUS

    Hello

    I've seen a lot of threads to display to change the color of the development of a list item.

    But I expect with change field items list in a different color than the default transparent. () When unfocus)

    Can someone help me?

    See you soon

    You can adjust the drawing in the drawListRow
    If you want a background, you can define one in the the domain manager

  • Listfield default blue color customization

    I'm trying to customize the color of the default blue to a list field. Its only come for the first line, but not for the other lines. Help, please.

    int [] cols = new int [] {0x7FBEFF, 0x7FBEFF, 0x00FFFFFF, 0x00FFFFFF};
    int [] xInds = new int [] {0, Display.getWidth (), Display.getWidth (), 0};
    int [] yInds = new int [] {0, 0, listnew.getRowHeight (), listnew.getRowHeight ()};

    If (listnew.getSelectedIndex () == index)
    {
    g.drawShadedFilledPath (xInds, null, yInds, null, COL);
    g.setColor (Color.BLACK);
    }
    listnew. Invalidate (index);

    Thnx everyone for your replies. I fixed it in way. I put this in the drawList method

    If (listnew.getSelectedIndex () == index)
    {
    g.setColor (0xff0033);
    g.fillRect (0, (index * listnew.getRowHeight (), Display.getWidth (), listnew.getRowHeight ());
    }
    listnew. Invalidate (index);

  • 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;
    }

  • Text in a line ListField

    After not having all the answers in this thread: http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=17423

    I thought I could try to use a ListField as a last resort, because, if you read the thread linked above, it seems that 4.2.1 has a bug where it will not change the background color of the Manager even if the word is invalid.

    However, I am having a hard time finding how I would wrap the text in a line ListField.  What I do is the following:

    [Bitmap] [Text text text text] [Bitmap]

    -[Text text text text]

    [Bitmap] [Text text text text] [Bitmap]

    -[Text text text text]

    [Bitmap] [Text text text text] [Bitmap]

    -[Text text text text]

    (Where '-' is just the space).

    I pray that I won't have to loop through the words in my channel and would be responsible for calculating the width each line wrapped.  I don't think also drawText with the style of the ellipse is suitable.

    Advice would be greatly appreciated.

    If anyone has the same problem, I came across this great piece of code: http://pastie.org/282759/wrap

  • 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...

  • Border around the selected ListField item?

    Hello

    I wonder if it is possible to customize a ListField, such as when you scroll through the list, the current row will have a border color around it?

    If this is not possible, I thought to imitate a ListField behavior using a TableLayout, where each row in the table has a HorizontalFieldManager.  Then, when an individual HorizontalFieldManager is selected, it will draw a border around it...

    Also, would it be possible to have a border around the current selected line (whether in a listfield or tablelayout) and then be able to select an object (such as a button) inside the line, without losing the border highlighted?

    Thank you!

    You might expect to have a special identification for the selected line in a ListField was asked and answered several times on this forum.  From memory, there are two options:

    (a) substitute drawfocus

    (b) in your drawListRow, check if the line that you draw is the selected line of the ListField.

    I suggest that you look in the forum for more information on these options.

    A ListField is a unique field, with a line at a time selected.  Without coding you something special it is not possible to have different parts of the line selected in different circumstances.  And although it is possible, don't normally add you a HorizontalFieldManager (or all other fields) to the ListField and which allows to paint content,

    What you're suggesting is indeed possible, but it is not for the faint-hearted.  I would recommend that investigate you other ways to achieve the desired effect before you start to look at using other fields to the layout and paint a line in the ListField.

Maybe you are looking for