Background ListField

Hello

I'm having trouble with the Community list across different versions of the OS.

OS 5 +.

Works perfectly.

OS 4.5 & 4.7

Whenever I do scroll and down my listfield (which is part of a verticalfield Manager who has a painting overloaded method that creates a black background), it runs in the background from black to white and never changes back. So if I scroll down the first three, they would be white, and the rest of the list would be black.

I wouldn't mind doing separate versions of my application, I wonder what I have to do to make this work on version 4.5/4, 7.

Heres my vfm

My apologies, I forgot to get back to you on this one.

I think I found this problem as soon as possible of the OS as well and replace my ListFields with the following code.  You will see that the idea is to get the ListField update at the moment where it appears it must and does not work.  I have no idea if this is necessary, I doubt it, but put it in there and see what happens when you delete a.  The last, which checks the size ListField, look a little weird, you might want to play with it.  I don't remember what was supposed to do. and is not this comment!

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

Called when the field receives focus.
{} public void onFocus (int direction)
super.onFocus (branch);
}

Called when a field loses focus.
public void onUnfocus() {}
super.onUnfocus ();
This.Invalidate (getSelectedIndex ());
}

protected void drawFocus (Graphics graphics, boolean on) {}
Do not press the accent if there is only one on the list
If (on & this.getSize () == 1) {}
return;
}
super.drawFocus(graphics, on);
}

Tags: BlackBerry Developers

Similar Questions

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

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

  • Problem with Listfield and expandable background bitmap

    Hello

    I struggled for a while to make this work, and after searching the forums and knowledge base, I can't seem to do right. What I try to do is:

    1 header is a bitmap expandable width of 1px to the bottom, more a company logo bitmap, with position fixed (only the items below it is scrolling)

    2. use a listfield, which contains 4 elements:

    -1 px wide image bitmap background for each line, repeat horizontally

    -1 px width bitmap image of background for the highlighted line, repeat horizontally

    -an icon bitmap for each line on the left side, and

    -a title text for each line

    Here is the screenshot and code what I've done so far, so the problem is:

    1. when I scroll, scrolls the header (what I want is to position of the header is fixed, only the listfield below is scrolling).

    2. the background image is only painted on the first line of the listfield, how can I do this with all the lines?

    3. How is - that replace you the default blue color on a bitmap background highlighted line?

    public class AjsScreen extends MainScreen{
    
        // constructor
        public AjsScreen() {
            super();
    
            // --- 1. Main Header --- \\
    
            //prepare images upfront
            final Bitmap bgHeader = Bitmap.getBitmapResource("bg-header.jpg"); // repeating background image for main header
            final Bitmap logoAjs = Bitmap.getBitmapResource("logo-ajs.png"); // company logo in main header
            final Bitmap bgMenu = Bitmap.getBitmapResource("bg-menu.jpg"); // repeating background image for main menu
            final Bitmap bgMenuRo = Bitmap.getBitmapResource("bg-menu-ro.jpg"); // repeating background image for main menu (highlighted)
    
            //images used as repeating background
            final Background backgroundHeader = BackgroundFactory.createBitmapBackground(bgHeader, 0, 0, Background.REPEAT_VERTICAL); //REPEAT HORIZONTAL ???
            Background backgroundMenu = BackgroundFactory.createBitmapBackground(bgMenu, 0, 0, Background.REPEAT_VERTICAL);
            Background backgroundMenuRo = BackgroundFactory.createBitmapBackground(bgMenuRo, 0, 0, Background.REPEAT_VERTICAL);
    
            //main header background, with stretched width, and fixed height
            HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH){
                public int getPreferredHeight() {
                    return 55;
                }
            };
            hfm.setBackground(backgroundHeader);
    
            //main header logo
            BitmapField bf = new BitmapField(logoAjs);
            bf.setPadding(2, 0, 0, 5);//clockwise from top, right, bottom, left
            hfm.add(bf);
    
            add(hfm);
    
            // --- 2. Main Menu --- \\
    
            ListField lf = new ListField(){ //4, USE_ALL_HEIGHT | USE_ALL_WIDTH
                protected void paint(Graphics graphics) {
                    // TODO Auto-generated method stub
                    super.paint(graphics);
                }
            };
            lf.setBackground(backgroundMenu);
            lf.setRowHeight(40);
    
            final Vector le = new Vector();
            le.addElement("Menu 1");
            le.addElement("Menu 2");
            le.addElement("Menu 3");
            le.addElement("Menu 4");
            le.addElement("Menu 5");
            le.addElement("Menu 6");
            le.addElement("Menu 7");
            le.addElement("Menu 8");
            le.addElement("Menu 9");
    
            lf.setCallback(new ListFieldCallback() {
                public int indexOfList(ListField listField, String prefix, int string) {
                    return le.indexOf(prefix, string);
                }
                public int getPreferredWidth(ListField listField) {
                    return Display.getWidth();
                }
                public Object get(ListField listField, int index) {
                    return le.elementAt(index);
                }
                public void drawListRow(ListField listField, Graphics g, int index, int y, int w) {
                    g.drawBitmap(0, y, bgMenu.getWidth(), bgMenu.getHeight(), bgMenu, 0, 0);
    
                    String text = (String) le.elementAt(index);
                    g.drawText(text, 0, y, 0, w);
                }
            });
    
            lf.setSize(le.size());
    
            add(lf);
    
        }
    
    }
    

    Thank you very much

    Yusuf

    «1. when I scroll, scrolls the header (what I want is in the position of the header is fixed, only the listfield below scrolls).»

    ListField will do this for you.  I suggest that you look at setTitle in the screen and put your part not scrolling in there

    '2. the background image is only painted on the first line of the listfield, how can I do this with all the lines?'

    Don't know (haven't looked hard) how your background is painted on the first line, but this line:

    g.drawBitmap (0, bgMenu.getWidth (), bgMenu.getHeight (), bgMenu, 0, 0);

    doesn't seem to work for your lines.  You need to paint the entire width like this.

    ". How do replace you line default highlighted in blue on a background bitmap? »

    There are a number of ways to do I think.  Is to determine if you paint the selected line and act accordingly

    (if (listField.getSelectedInde () == index) {...})

    } else {}

    }

    Some people I think drawFocus override for the ListField - if you're looking for tour you will find examples.

    I think there are other ways, I'm looking round I think that this question has been asked before.

  • ListField setting background + transparency.

    Hello

    Is it possible to make components such as translucent ListFields? (don't know if that's the right term when talking about UIS)

    Thank you

    Teja.

    Edit: Elaborate a little bit...

    1. I have a ListField I want to put a white background. How can I do this? I'm already implement ListFieldCallBack and I have overridden drawListRow. I tried to do g.setBackground (Color.WHITE), but this doesn't seem to work...

    Edit2: The substitution of paintBackground() and using g.setBackground tried it. Still does not work.

    2. then, I want to increase the transparency of the ListField lines so that the background is visible. I was going through the methods of the graphics class and tried g.setGlobalAlpha (100), but that doesn't seem to work.

    Thanks again,

    Teja.

    You call Graphics #clear () after you set the background color?

    Graphics #SetBackgroundColor () key Graphics #clear ().

    Graphics #setColor () touch Graphics.draw* ().

  • Background thread which problems refreshing ListField!

    I created a screen that uses a listfield to display the contents of a persistent vector object.

    And now I have an application when the condition is appropriate to remove a vector object. The vector is belong to the lisfield.

    It's my code.

    public class LittleAlarmBackgroundApp extends Application implements
            RealtimeClockListener {
    
        private Vector _alarms;
        private RuntimeStore rs;
        private AlarmListField alf;
    
        public LittleAlarmBackgroundApp() {
    
                     ...                 _alarms = (Vector)_database.getContents();        rs = RuntimeStore.getRuntimeStore();  }
    
      public static void main(String[] args) {
    
                LittleAlarmBackgroundApp bg = new LittleAlarmBackgroundApp();         bg.enterEventDispatcher();
    
        }
    
      public void clockUpdated() {
    
                   ...
    
        if(am.getHour()==hour && am.getMinute() == minute)          {                 if(am.get_type()==1) {    _alarms.removeElementAt(i);//_alarms is a vector that is belong to listfield  alf = (AlarmListField)rs.get(list_key);//alf is a listfield   if(alf != null) {                                  alf.updateList();//this method called setSize() of ListFild                  //AlarmListField(Field).assertHaveEventLock() line: 6067                 //  there is a exception that called IlleaglStateException
    
                      }             }         }     }     am = null;        c = null; }
    
        }}
    

    I want my background thread removes the element of the vector persistent and updating of the size of ListFied so that ListField can update!

    Please help me!

    Instead of

    alf.updateList ();

    follow these steps:

    Application.getApplication (.invokeLater)

    new Runnable() {}

    public void run() {}

    alf.updateList ();

    }

    }

    );

    A slight efficiency would be to declare the executable as a member of LittleAlarmBackgroundApp and then pass the object to invokeLater():

    private AlarmListField alf;

    private Runnable Updater = new Runnable() {}

    public void run() {}

    alf.updateList ();

    }

    }

    - - -

    Application.getApplication () .invokeLater (updater).

  • 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

  • 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

  • Static background with VerticalFieldManager

    Hello, I would like to set up a background image for my application, where it must not move even when the user scrolls... I found the following code on the internet for this type of Manager:

    package com.kruger.workflow.gui;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    public class BGVerticalFieldManager extends VerticalFieldManager {
        Bitmap mBgBitmap = null;
        int mBgWidth = -1;
        int mBgHeight = -1;
        int mBgX = -1;
        int mBgY = -1;
    
        public BGVerticalFieldManager(Bitmap background) {
            super(USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL
                    | VERTICAL_SCROLLBAR);
            mBgBitmap = background;
            mBgWidth = mBgBitmap.getWidth();
            mBgHeight = mBgBitmap.getHeight();
            mBgX = (Display.getWidth() - mBgWidth) >> 1;
            mBgY = (Display.getHeight() - mBgHeight) >> 1;
    
        }
    
        protected void paintBackground(Graphics graphics) {
            paintBackgroundBitmap(graphics);
            invalidate();
        }
    
        private void paintBackgroundBitmap(Graphics graphics) {
            if (null != mBgBitmap) {
    
                int x = mBgX
                        + getHorizontalScroll();
    
                int y = mBgY
                        + getVerticalScroll();
                 graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
            }
        }
    }
    

    However, does not work... I get the following results:

    As you can see the image begins to scroll backwards...

    The use of this Manager is:

    Bitmap bitmap = Bitmap.getBitmapResource("1.jpg");
            add(mContainer = new BGVerticalFieldManager(bitmap));
            for (int i = 0; i < 100; i++) {
                mContainer.add(new LabelField("List item #" + String.valueOf(i)));
                mContainer.add(new SeparatorField());
            }
    

    Although no result so far... When debugging the code, I noticed that this line:

    if (null != mBgBitmap) {
    
                int x = mBgX
                        + getHorizontalScroll();
    
                int y = mBgY
                        + getVerticalScroll();
                 graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
            }
    

    Always returns 0 for both a XY is not assumed that getVerticalScroll or getHorizontalScroll must return aware of gap between the container Manager.? How can I fix this?

    Thank you very much.

    I use a VOR with USE_ALL_HEIGHT and NO_VERTICAL_SCROLL and set the background image to it (using the BackgroundFactory since 5.0)

    in this optimization of resources, I put a second, but it work with VERTICAL_SCROLL. The listfield (or any content) is put there.

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

  • stop scrolling background image

    Hello

    In my application, I used a custom manager that contains the listField object. The problem is that when I scroll through the on-screen image begins to repeat until the length of the list (which is dynamic). I don't want the wallpaper to scroll but I don't want the nursery and its content to scroll on the same single image.

    Can u please help me?

    Thanks in advance

    Hi and welcome to the forums!

    I recommend that search you the forum (using the search service you will see near the top right) to get answers to your question before posting.  Especially when you're new, someone else will be asked the same questions.  In fact, there are a number of similar threads on the forum and this article:

    http://supportforums.BlackBerry.com/T5/Java-development/use-a-background-image-in-application-screen...

    have a look at this and other Threads you will find and come back if you cannot fix yourself.

    Good luck.

  • Scrolling ListField

    I read many more posts scrolling ListField and they helped me to get that much, but now I'm stuck.  I have my list field in a VerticalManager with scroll work.  I set it up so that there are 5 visible rows in the ListField.  However, when I scroll down past the last visible line (there is currently a total of 9 lines of the list), paint lines is no longer the text of the line.  I developed a custom implementation ListField, who has a foreground and background color.  The idea is that each line is focused, switch foreground and background of color - the selected line a deep Navy with white text and unselected lines have a white background with marine text.  Works very well for the visible rows, but when I scroll beyond rank 5 to reveal the invisible lines, they just paint with the Navy background and white text.  Here's my class of custom list field (which was based on something that I found on a forum or in the knowledge base):

    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.XYRect;
    Import net.rim.device.api.ui.component.ListField;

    SerializableAttribute public class ColoredListField extends ListField
    {
    Private boolean hasFocus = false;
    Private final int fixedWidth;
    private int fgcolor;
    private int bgcolor;
    Private final int fixedHeight;

    public ColoredListField (int width, int height, int fgcolor, bgcolor int)
    {
    this.fixedWidth = width;
    this.fixedHeight = height;
    This.fgColor = fgcolor;
    This.BgColor = bgcolor;
    }

    public int getPreferredWidth()
    {
    return fixedWidth;
    }

    public void layout (int width, int height)
    {
    setExtent (fixedWidth, fixedHeight);
    }

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

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

    Public Sub onUnfocus()
    {
    hasFocus = false;
    super.onUnfocus ();
    Invalidate();
    }

    public void paint (Graphics graphics)
    {
    Get current cutting zone because it will be the only party which
    need to repaint
    XYRect redrawRect = graphics.getClippingRect ();
    If (redrawRect.y<>
    throw IllegalStateException (new)
    ' The variable 'y' clipping ' +.
    "rectangle is.< 0:="" "="" +="">

    If the ListField has focus determine the selected line.
    rowHeight = getRowHeight() int;
    int currEntry = redrawRect.y / rowHeight.
    int lastVisibleEntry = (redrawRect.y + redrawRect.height - 1) / rowHeight.
    lastVisibleEntry = Math.min (lastVisibleEntry, getSize() - 1);
    int y = currEntry * rowHeight.

    int curSelected = hasFocus? getSelectedIndex():-1;
    Draw each line
    for (; currEntry<= lastvisibleentry;="">
    {
    graphics.setColor (currEntry == curSelected? bgcolor: fgcolor);
    graphics.fillRect (0, y, redrawRect.width, rowHeight);
    graphics.setColor (currEntry == curSelected? fgcolor: bgcolor);
    graphics.drawText (getCallback () .get (this, currEntry) m:System.NET.SocketAddress.ToString (), 0,)
    y);
    Assign new values for the y-axis move a row downwards.
    y += rowHeight.
    }
    }
    }

    Here's how I instantiated class:

    private int screenW = Graphics.getScreenWidth ();
    private int screenH = Graphics.getScreenHeight ();
    private int listWidth = (int) (screenW * 0.95);
    private int listHeight = (int) (screenH * 0.4).
    private ColoredListField myListField = new ColoredListField)
    listWidth, listHeight, selectedFGColor, selectedBGColor);

    Also, here is my point:

    private static class DiaryEntryListCallback implements ListFieldCallback
    {
    private DiaryEntry [diaryEntryList];

    public DiaryEntryListCallback() throws Exception
    {
    diaryEntryList new = DiaryEntry [0];
    init();
    }

    public void init() bird Exception
    {
    DiaryEntry [] tmpDiaryEntryList =
    DiaryDAO.instance () .getDiaryEntriesAsArray (true);
    If (tmpDiaryEntryList! = null & tmpDiaryEntryList.length > 0)
    diaryEntryList = tmpDiaryEntryList;
    on the other
    {
    diaryEntryList = new DiaryEntry [1];
    diaryEntryList [0] = new DiaryEntry ("No data",
    Calendar.getInstance ());
    }
    }

    public void init (DiaryEntry [diaryEntries]) throws exceptions
    {
    diaryEntryList = diaryEntries;
    }

    public int getNumberOfRows()
    {
    Return diaryEntryList.length;
    }

    ' Public Sub drawListRow (ListField l, Graphics g, int index, int y, int w)
    {
    draw text is managed by the implementation of the custom list field
    }

    public {get {Object (ListField listField, int index)
    {
    return diaryEntryList [index];
    }

    public int getPreferredWidth (ListField listField)
    {
    Return listField.getPreferredWidth ();
    }

    public int indexOfList (String prefix, ListField listField, int start)
    {
    int size = diaryEntryList.length;
    for (int i = 0; i)< size;="">
    {
    DiaryEntry currEntry = diaryEntryList (DiaryEntry) [i];
    If (currEntry.getEntryText () .toLowerCase () .startsWith)
    (prefix.toLowerCase ()))
    Return i;
    }
    Return listField.getSelectedIndex ();
    }
    }

    And here's where I build the main screen, adding the list field and other areas:

    Private Sub createMainScreen()
    {
    mainMgr = new ColoredVerticalManager (selectedBGColor,
    Manager.USE_ALL_HEIGHT);
    listMgr = new ColoredVerticalManager)
    selectedBGColor,
    Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    mainMgr.add (diaryEntriesLabel = new FixedWidthLabelField)
    "' Diary entries:»(, listWidth,-1, selectedFGColor, selectedBGColor));"
    Try
    {
    listCallback = new DiaryEntryListCallback();
    diaryEntriesListField.setSize (listCallback.getNumberOfRows ());
    diaryEntriesListField.setCallback (listCallback);
    diaryEntriesListField.setFocusListener (new DiaryFocusListener());
    listMgr.add (diaryEntriesListField);
    mainMgr.add (listMgr);
    }
    catch (System.Exception e)
    {
    Dialog.Alert ("error when loading of list one diary entry:" + e.getMessage ());
    }
    mainMgr.add (selectedEntryLabel = new FixedWidthLabelField)
    ((' Selected: input: ",-1, -1, selectedFGColor, selectedBGColor));
    mainMgr.add (diaryEntry);
    Add (mainMgr);
    }

    Clues as to why when scrolling past the visible lines, he stops painting?

    Thank you

    Steve

    Hello

    You want listfield fixed size with active scroll.

    Please try the following solution:

    Removed listfield class the following function:

    public void layout (int width, int height)
    {
    setExtent (fixedWidth, fixedHeight);
    }

    That you override the trace of the listfield, the measure will be defined as a fixed height. Therefore, you have noticed that Manager of vertical field scrolls but listfield not scroll.

    Please override method 'sublayout' of vertical field Manager "listmgr":
    VerticalFieldManager oVerticalFieldManager = new VerticalFieldManager (MainScreen.VERTICAL_SCROLL |) MainScreen.VERTICAL_SCROLLBAR)
    {
    public int getPreferredHeight()
    {
    Return nFixedHeight;
    }
               
    Rewritten to define the visible height for the vertical field Manager.
    protected void sublayout (int width, int height)
    {
    height = nFixedHeight;
    Super.sublayout (width, height);
    setExtent (width, height);
    }
    };

    This code works for me fine.

    Kind regards
    Shubhangi

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

  • Refresh ListField and store multiple entries

    I'm having a problem trying to get my program to save the information. I recently ended show him an entry but I don't think that im doing something because it shows just the same entry over and over again.

    Im trying to to save all fees in the form of spending and then display them in the WelcomeScreen listbox. I'll include the store file, welcomeScreen and booking fees.

    What would be the best way to store this information and display them in the listfield? Also when you return to the WelcomeScreen how can I have the update so the listfield is updated?

    WelcomeScreen:

    package moneyMasterApp;
    
    import java.util.Vector;
    
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.decor.*;
    
    public class WelcomeScreen extends UiApplication implements StoreResource {
        //Declare Variables
        //create a button here with the text 'Submit!'
            //ButtonField.CONSUME_CLICK will prevent the Menu from showing up when the user clicks the button.
            ButtonField btnDeposit = new ButtonField("Deposit", Field.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
            ButtonField btnExpense = new ButtonField("Expense", Field.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
            UiApplication nxtscreen = UiApplication.getUiApplication();
            HorizontalFieldManager _FieldManagerTop;
            LabelField myTitleLabel;
            BitmapField bitpam = new BitmapField();
            Background bg;
            LabelField label = new LabelField("Please Select Action:");
            FieldListener listener = new FieldListener();
            private static Vector _data;
            private static PersistentObject store;
            private ListField ExpenseList = new ListField();
    
        public static void main(String[] arg) {
            WelcomeScreen app = new WelcomeScreen();
            app.enterEventDispatcher();
        }
    
        public WelcomeScreen() {
            MainScreen mainScreen = new MoneyMakerMainScreen();
            //Set the title of the screen
            mainScreen.setTitle("MoneyMaster");
            //Add labels and other items
            _FieldManagerTop = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL);
            myTitleLabel = new LabelField("MoneyMaster");
            bitpam = new BitmapField();
            bitpam.setBitmap(Bitmap.getBitmapResource("bbicon.png"));
            _FieldManagerTop.add(myTitleLabel);
            _FieldManagerTop.add(bitpam);
            bg = BackgroundFactory.createLinearGradientBackground(0x2ebaeb, 0x2ebaeb, 0x7cbaed, 0x7cbaed);
            mainScreen.getMainManager().setBackground(bg);
    
            synchronized(store) {
                Vector _data = (Vector) store.getContents();
                int count = _data.size();
                ExpenseList.setEmptyString("Nothing", DrawStyle.LEFT);
                ExpenseList.setSize(count);
            }
    
            ExpenseList.setCallback(new ExpenseListCallback());
    
            //Add objects to screen
            mainScreen.add(_FieldManagerTop);
            mainScreen.add(label);
            mainScreen.add(new SeparatorField());
            btnDeposit.setChangeListener(listener);
            btnExpense.setChangeListener(listener);
            mainScreen.add(btnDeposit);
            mainScreen.add(btnExpense);
            mainScreen.add(new SeparatorField());
            mainScreen.add(ExpenseList);
            pushScreen(mainScreen);
    
        }
    
        static {
            //Retrieve a reference to a persistent object
            //and set its contents to a new new vector if it is empty
            store = PersistentStore.getPersistentObject(0xe69c43e620187619L);
            //Hash of: "TechStormSolutions.MoneyMaster.Application"
            synchronized(store) {
                if (store.getContents() == null) {
                    store.setContents(new Vector());
                    store.commit();
                }
            }
            //retrieve the contents of the PersistentObject
            //and store in a Vector
            _data = new Vector();
            _data = (Vector)store.getContents();
        }
    
        private final class MoneyMakerMainScreen extends MainScreen {
            protected void makeMenu (Menu menu, int instance) {
                menu.add(deposit);
                menu.add(expense);
                super.makeMenu(menu, instance);
            }
    
            public void close() {
                Dialog.alert("Closing Application");
                super.close();
            }
        }
    
        private MenuItem deposit = new MenuItem("Deposit", 1, 100) {
            public void run() {
                UiApplication.getUiApplication().pushScreen(new depositForm());
            }
        };
        private MenuItem expense = new MenuItem("Expense", 2, 101) {
            public void run() {
                UiApplication.getUiApplication().pushScreen(new expenseForm());
            }
        };
    
        class FieldListener implements FieldChangeListener {
    
            public void fieldChanged(Field f, int context) {
                //if the deposit button is clicked
                if (f==btnDeposit) {
                    UiApplication.getUiApplication().pushScreen(new depositForm());
                };
                if (f==btnExpense) {
                    UiApplication.getUiApplication().pushScreen(new expenseForm());
                }
            }
    
        }
    
        final class ExpenseListCallback implements ListFieldCallback {
    
            public void drawListRow(ListField list, Graphics g,
                    int index, int y, int w) {
                int count = _data.size();
    
                synchronized(store) {
                    Vector _data = (Vector) store.getContents();
                    if (!_data.isEmpty()) {
                        String[] ExpList = new String[count];
                        for (int i = 0; i < count; ++i) {
                            StoreInitial info = (StoreInitial) _data.elementAt(i);
                            ExpList[i] = info.getElement(StoreInitial.AMOUNT);
                        }
    
                        g.drawText(ExpList[0], 0,y,0,w);
                    }
                }
    
            }
    
            public Object get(ListField listField, int index) {
                return null;
            }
    
            public int getPreferredWidth(ListField listField) {
                return Display.getWidth();
            }
    
            public int indexOfList(ListField listField, String prefix, int start) {
                return listField.indexOfList(prefix, start);
            }
    
        }
    }
    

    In my listcallback I had to change that loop and out so that the index was the counter.

    synchronized(store) {
                    Vector _data = (Vector) store.getContents();
                    if (!_data.isEmpty()) {
                        String[] ExpList = new String[index];
                        StoreInitial info = (StoreInitial) _data.elementAt(i);
                        g.drawText(info.getElement(StoreInitial.AMOUNT), 0,y,DrawStyle.RIGHT,w);
                    }
                }
    

Maybe you are looking for