Skip to main content

Blackberry Creating Toolbar Part 1

Update  Oct-9-2012

* I think i should make this tutorial into parts. Part 1 should be for beginner, the higher part should be for advanced coder *
-----------------------------------------------------------------------------------------------------
Requirements :

- BlackBerry OS 5

Right now I want to create Toolbar just like this

 
What i really want to create Toolbar with Back Button, Screen Name and some Align Right Button or Text. and of course with fixed position.


Right now i don't really have a solution to create amazing toolbar but right now I'm using GridFieldManager to create a simple toolbar. but I'll update this soon i got the solution and i hope with a cool layout.

This is the First Code

// CODE SUPPOSED TO BE HERE
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class HeaderTest extends MainScreen {

    /**
     * 
     */
    public HeaderTest() {
        super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
        // TODO Auto-generated constructor stub
        HeaderStyle1();
        
    }
    
    public void HeaderStyle1(){
        /*
         * This Style Should be Consist <backButton> ScreenName <otherButton>
         * And Using GridFieldManager
         */
        GridFieldManager gfm = new GridFieldManager(1, 3, 0);
        //gfm.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0,0,0,0),Border.STYLE_DASHED));
        
        int columnWidth1 = (int) ((Display.getWidth() * 0.2) - gfm.getColumnPadding());
        int columnWidth2 = (int) ((Display.getWidth() * 0.6) - gfm.getColumnPadding());
        int columnWidth3 = (int) ((Display.getWidth() * 0.2) - gfm.getColumnPadding());
        //int totalCol = gfm.getColumnCount();
//         for(int i = 0; i < totalCol; i++) {
//            gfm.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
//         }
        //gfm.setBackground(BackgroundFactory.createSolidBackground(0xA3080C));
        gfm.setColumnProperty(0, GridFieldManager.FIXED_SIZE, columnWidth1);
        gfm.setColumnProperty(1, GridFieldManager.FIXED_SIZE, columnWidth2);
        gfm.setColumnProperty(2, GridFieldManager.FIXED_SIZE, columnWidth3);
        gfm.isStyle(GridFieldManager.USE_ALL_WIDTH);
        ButtonField backButton = new ButtonField("Back",ButtonField.CONSUME_CLICK | DrawStyle.ELLIPSIS);
        gfm.add(backButton);
        
        LabelField labelTitle = new LabelField("Screen Name");
        Font myFont = labelTitle.getFont();
        FontFamily fontFam;
        try {
            fontFam = FontFamily.forName("System");
            myFont = fontFam.getFont(Font.BOLD,28);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
        }
        labelTitle.setFont(myFont);
        gfm.add(labelTitle);
        ButtonField cartButton = new ButtonField("Cart",ButtonField.CONSUME_CLICK | DrawStyle.ELLIPSIS);
        gfm.add(cartButton);
        
        FieldChangeListener backBtnListener = new FieldChangeListener() {
            
            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                Dialog.inform("Back Button is Pushed");
            }
        };
        backButton.setChangeListener(backBtnListener);
        
        FieldChangeListener cartBtnListener = new FieldChangeListener() {
            
            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                Dialog.inform("Cart Button is Pushed");
            }
        };
        cartButton.setChangeListener(cartBtnListener);
        add(gfm);
    }
    
    public boolean onClose() {
        setDirty(false);
        return super.onClose();
    }
    
}


This is my First Result


As you see the code i'm using GridFieldManager to handle Fields (Button Field, Label Field, etc). Other things is pretty much simple.

Thanks.

See the Part 2 of the tutorial. the part 2 will be using a simple style to create colorfull toolbar. well its not really colorful. i just add background color.. :p

Go to Part 2

Comments

Popular posts from this blog

JavaScript Real Time Calculation

I've been around looking for javascript that can do Real Time Calculation. javascript real time calculation, javascript real time calculation textbox. by some lucky keywords i found this code. this is exactly the code that i want. it really do the real time calculation. and it doesn't need onChange or OnBlur function. Just try it Example + = this is the javascript code <script type='text/javascript' > function startCalc(){   interval = setInterval("calc()",1); } function calc(){   one = document.autoSumForm.firstBox.value;   two = document.autoSumForm.secondBox.value;   document.autoSumForm.thirdBox.value = (one * 1) + (two * 1); } function stopCalc(){   clearInterval(interval); } </script> this is the html code <form name="autoSumForm">   <input class="right" type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br>

Learning Odoo 13 Module Development and Review

USING ODOO 13 Introduction This writing supposed to be a cheat sheet for helping myself to learn about Odoo, Odoo Development and also anyone who want to read this.   Odoo already have a good documentation in their websites you can check it here https://www.odoo.com/documentation/13.0/ What you need Odoo source you can get the source from odoo.com or github https://www.odoo.com/page/download or https://github.com/odoo/odoo. Right now I'm using the  https://www.odoo.com/page/download  . I did using the github twice so I'm already familiar with it but now i want to explore something new and maybe we will find something. Python v3.6++ (intermediate level). https://www.python.org/downloads/windows/ You can learn some basic “web development with python” first if you still new at programming. Search with google. Postgresql https://www.postgresql.org/download/ I’m using win Os for development and Visual Studio Code for IDE What should you re

BlackBerry ListField Tutorial Part 2

Blackberry ListField with Clicked Row this time i create based on rtm4bb code. it used manager as TableRowManager to create the field for each row. first i create MenuListField.java