Click here to Skip to main content
15,893,994 members
Articles / Web Development / ASP.NET

End-to-End Real World BlackBerry Application, Part 1

Rate me:
Please Sign up or sign in to vote.
4.20/5 (7 votes)
25 Jun 2008CPOL4 min read 63.7K   287   50  
End-to-end real world BlackBerry application walkthrough.
package KnowledgeBase;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.Bitmap;

class HomeScreen extends MainScreen  {
    
    private String mnuSearchTitles;
    private String mnuBrowseTags;
    private String mnuViewRecent;
    private String[] mainMenuItems;
    private MyObjectListField menu;
    
    
    HomeScreen() {
        
        this.setTitle("KnowledgeBase");
        
        menu = new MyObjectListField();
        mnuSearchTitles = "Search by Title";
        mnuBrowseTags = "Browse Tags";
        mnuViewRecent = "View Recent";
        mainMenuItems = new String[]{mnuSearchTitles,mnuBrowseTags,mnuViewRecent};
        menu.set(mainMenuItems);
        this.add(menu);
    }
    
    protected boolean navigationClick(int status, int time) {
        
        // Determine which menu item was clicked.
        int selected = menu.getSelectedIndex();
        switch (selected) {
            case 0:
                // TODO: Show the Search Screen.
            break;
            case 1:
                // TODO: Show the Browse Tags Screen.
            break;
            case 2:
                // TODO: Show the Results Screen and load the 
                // recently viewed items.
            break;
        }
        
        return true;
    }
    
    private class MyObjectListField extends ObjectListField {
        
        private Bitmap icon = Bitmap.getBitmapResource("img/star_green.png");                
        
        // We are going to take care of drawing the item.
        public void drawListRow(ListField listField, Graphics graphics, 
                int index, int y, int width) {
            if (null != icon) {
                int offsetY = (this.getRowHeight() - icon.getHeight())/2;
                graphics.drawBitmap(1,y + offsetY, icon.getWidth(),
                        icon.getHeight(),icon,0,0);
                graphics.drawText(mainMenuItems[index], 
                    icon.getWidth() + 2, y, DrawStyle.ELLIPSIS, width);
            } else {
                graphics.drawText("- " + mainMenuItems[index], 0,
                    y, DrawStyle.ELLIPSIS, width);
            }
        }
    };
    
} 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
United States United States
I run a small development team for an international Law Firm.

Comments and Discussions