Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4249798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:26:40+00:00 2026-05-21T04:26:40+00:00

I have a question about ListField : If I call setSize(16) then I indicate,

  • 0

I have a question about ListField:

If I call setSize(16) then I indicate, how many items this component contains. How do I control the height of this component then?

For example I use the code below to display a TextField and a ListField below, but I also would like to show a ButtonField underneath the ListField:

enter image description here

MyScreen.java:

private MyList presetList = new MyList();

private MyScreen() {
    setTitle("Favorites");

    BasicFilteredList filterList = new BasicFilteredList();        
    String[] days = {"Monday","Tuesday","Wednesday",
                     "Thursday","Friday","Saturday","Sunday"};
    int uniqueID = 0;
    filterList.addDataSet(uniqueID,days,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);
    AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
    add(autoCompleteField);        

    presetListField.setRowHeight(-2);
    presetListField.setCallback(presetList);
    presetListField.setSize(MyList.items.length());
    add(presetListField);
}

MyList.java:

public class MyList implements ListFieldCallback {
    public static String items[] = {
            "Favorite 01", "Favorite 02", "Favorite 03", "Favorite 04",
            "Favorite 11", "Favorite 12", "Favorite 13", "Favorite 14",
            "Favorite 21", "Favorite 22", "Favorite 23", "Favorite 24",
            "Favorite 31", "Favorite 32", "Favorite 33", "Favorite 34"
    };

    public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
        Font f = g.getFont();
        Font b = f.derive(Font.BOLD, f.getHeight() * 2);

        g.setColor(Color.WHITE);
        g.drawText(items[index], Display.getWidth()/3, y);
        g.drawText("Click to get frequency", Display.getWidth()/3, y + g.getFont().getHeight());

        g.setFont(b);
        g.setColor(Color.YELLOW);
        g.drawText("100." + index, 0, y);
     }

     public Object get(ListField list, int index) {
         return items[index];
     }

     public int indexOfList(ListField list, String p, int s) {
         return -1;
     }

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

Thank you!
Alex

UPDATE:

Maybe ListField is supposed to always show all its items and you can’t limit its view to few rows?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:26:40+00:00Added an answer on May 21, 2026 at 4:26 am

    This is probably not exactly what you request for, but could you try to put your button into the status container of your screen? This would be the easiest way to have the button in the bottom of the screen. However in this case the button will stay there regardless of the list size (number of items).

    Class MainScreen

    public void setStatus(Field status)

    Sets the contents of this screen's status section.
    
    This method adds your provided field to this screen's status section, 
    even if it already contains a field.
    
    Parameters:
        status - New status field.
    

    UPDATE:

    You are asking why this is as it is. Well, as I see it this was an RIM’s attempt to implement some sort of MVC (Model-View-Controller) pattern. Undoubtedly it is not ideal. ListField is an old core BB API class which has not changed for years. I think if they had a second chance the API would be much better. For instance, on Android lists APIs are much better. I also find ListField.setSize() a bit ugly, but we can not change this and it is up to us to manually instruct the ListField that the underlying list has changed its size.

    A point about ListFieldCallback usage. With this approach ListField itself knows nothing about what list items actually are. It is up to ListFieldCallback to return a list item object on request or to draw a list item representation on request. Note this happens on request. ListField asks the ListFieldCallback to draw only those items which are visible on the screen. This is very important in terms of speed and RAM usage. If your list is 1000 items and each item implies drawing an icon which should be loaded from the network (or just read from the filesystem), then preparing the whole list data at once whould be a show-stopper. But with ListFieldCallback you are able to process only those items which are requested, so you can implement lazy-loading and your list becomes as quick as possible.

    For some simple cases (when your listItem UI representation can be got just by calling listItem.toString()) there is the ObjectListField class. This class already implements the ListFieldCallback, so it displays the list right out of the box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about locking. This doesn't have to be only about record
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about this question . I posted a reply there but
I have this question about umbraco structuring and I can't find the answer anywhere.
I have a question about my MSDN Premium Subscription. This is what I want
Have a question about linux bash. I want to start a program and then
i have question about finding maximum x or y-value in text file. This is
Today I have question about Eclipse . I use this IDE very long and
I have a question about this script I found and used. It works but
https://stackoverflow.com/a/64983/468251 - Hello, I have question about this code, how made that working with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.