java me - Custom layout in blackberry -


i need custom layout below in blackberry.

enter image description here

i did same layout in android. need same layout in blackberry. new blackberryapp development. fields of blackberry views in android seem confusing things me.

i tried verticalfieldmanager & horizontalfieldmanager mixing these bitmapfield & labelfield produce layout.

i failed particularly in placing labelfield @ bottom of screen. used use_all_height & field_bottom style put @ bottom, showing after scrolling long time.

my requirement header , footer should not scroll when middle list scrolling.

the easiest way add header , footer fields don't scroll content in middle of screen use mainscreen#setbanner() , mainscreen#setstatus().here's example:

public class headerfooterlistscreen extends mainscreen {     private static final int bg_color = color.black;    private static final int highlight_color = color.blue;    private static final int font_color = color.white;    private static final int row_height = 60;     private object[] _rowdata;    private field _header;    private field _footer;    private field _spacer;    private int _orientation;     public headerfooterlistscreen() {       super(mainscreen.vertical_scroll | mainscreen.vertical_scrollbar);        background bg = backgroundfactory.createsolidbackground(bg_color);       setbackground(bg);       getmainmanager().setbackground(bg);        // header       bitmap headerimg = bitmap.getbitmapresource("header.png");       _header = new bitmapfield(headerimg);       setbanner(_header);        // list       _rowdata = new object[] { "row one", "row two", "row three" }; //, "row four", "row five", "row six", "row seven", "row eight", "row nine", "row ten" };       listfield list = new listfield();       int c = color.red;       xyedges edgecolors = new xyedges(c, c, c, c);       xyedges edgethicknesses = new xyedges(5, 5, 5, 5);       list.setborder(borderfactory.createsimpleborder(edgethicknesses, edgecolors, border.style_solid));       list.setcallback(new customlistfieldcallback());       list.setrowheight(row_height);       list.setsize(_rowdata.length);        add(list);        // footer       _footer = new labelfield("footer showing status text", field.use_all_width | drawstyle.hcenter) {          public void paint(graphics g) {             // change font color             int oldcolor = g.getcolor();             g.setcolor(font_color);             super.paint(g);             g.setcolor(oldcolor);          }       };       _footer.setfont(_footer.getfont().derive(font.plain, 24));       setstatus(_footer);    }         private void centerlist() {       if (_spacer != null && _spacer.getmanager() != null) {          // delete old spacer field, if there 1                delete(_spacer);            }       int listheight = _rowdata.length * row_height;       int availableheight = getheight() - _footer.getheight() - _header.getheight();        if (availableheight > listheight) {          boolean firstrun = (_spacer == null);          // add spacer above list force down enough centered          final int space = (availableheight - listheight) / 2;                   _spacer = new field() {             protected void layout(int width, int height) {                setextent(width, space);                           }             protected void paint(graphics graphics) {                         }                      };          insert(_spacer, 0);           if (firstrun) {             getmainmanager().setverticalscroll(0);          }       }    }        // called when device orientation changes    protected void sublayout(int width, int height) {       super.sublayout(width, height);        if (_orientation != display.getorientation()) {          _orientation = display.getorientation();           // run invokelater() avoid recursive sublayout() calls          uiapplication.getuiapplication().invokelater(new runnable() {             public void run() {                // todo: may have adjust header, too?                centerlist();             }          });       }    }     private class customlistfieldcallback implements listfieldcallback {        private final int pad = 10;        public void drawlistrow(listfield listfield, graphics graphics,             int index, int y, int width) {           int oldcolor = graphics.getcolor();          if (listfield.getselectedindex() == index) {             graphics.setcolor(highlight_color);          } else {             graphics.setcolor(bg_color);          }          graphics.fillrect(0, y, width, listfield.getrowheight());           graphics.setcolor(font_color);          string text = (string)get(listfield, index);                         graphics.drawtext(text, pad, y + pad, drawstyle.left);           graphics.setcolor(oldcolor);       }        public object get(listfield listfield, int index) {          return _rowdata[index];       }        public int getpreferredwidth(listfield listfield) {                   return display.getwidth();       }        public int indexoflist(listfield listfield, string prefix, int start) {                   return -1;  // todo?       }    } } 

you didn't specify how wanted list in middle work, made guesses. wasn't sure if red border wanted, or used describe layout. edit question, or post new question, if have more requirements list.

field concepts

if you're coming android, , unclear role of blackberry ui classes, fields , managers, here's resources:

results

enter image description here


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -