⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tagsscreen.java

📁 In the last three articles, I’ve been walking you through the creation of an end-to-end BlackBerry a
💻 JAVA
字号:
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 TagsScreen extends MainScreen {
    
    private Tag[] tags;
    private TagsListField tagsList;
    private ArticlesScreen articlesScreen;
    
    private MenuItem getArticlesMenu = new MenuItem("Get Articles",100,10) {
       public void run() {
           getArticles();
       } 
    };
    
    TagsScreen(ArticlesScreen articlesScreen) {    
        
        this.articlesScreen = articlesScreen;
        this.setTitle("Tags");
        
        // Create a few dummy tags in order to test the screen;
        tags = new Tag[15];
        Tag tag;
        for (int i = 0; i < 15; i++) {
            tag = new Tag();
            tag.name = "Dummy tag " + Integer.toString(i);
            tag.count = i + 1;
            tags[i] = tag;
        }
        
        tagsList = new TagsListField();
        tagsList.set(tags);
        this.add(tagsList);
    } 
    
    protected boolean navigationClick(int status, int time) {
        Field focus = this.getLeafFieldWithFocus();
        if (focus == tagsList) {
            getArticles();
            return true;
        }
        return false;
    }   
    
    protected void makeMenu(Menu menu, int instance) {
        menu.add(getArticlesMenu);
        menu.add(MenuItem.separator(getArticlesMenu.getOrdinal() + 1));
        super.makeMenu(menu,instance);
    }
    
    private void getArticles() {
        int selected = tagsList.getSelectedIndex();
        if (selected > -1) {
            Tag selectedTag = (Tag)tagsList.get(tagsList,selected);
            UiApplication.getUiApplication().pushScreen(articlesScreen);
            // TODO: trigger the search function in the Articles Screen.
        }
    }
    
    private class Tag {
        public String name;
        public int count;
    };
    
    private class TagsListField extends ObjectListField {
        
        private Bitmap icon = Bitmap.getBitmapResource("img/tag_yellow.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(tags[index].name + " (" + Integer.toString(tags[index].count) + ")", 
                    icon.getWidth() + 2, y, DrawStyle.ELLIPSIS, width - icon.getWidth() + 2);
            } else {
                graphics.drawText("- " + tags[index].name + " (" + Integer.toString(tags[index].count) + ")", 0,
                    y, DrawStyle.ELLIPSIS, width - graphics.getFont().getAdvance("- "));
            }
        }
    };
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -