65.9K
CodeProject 正在变化。 阅读更多。
Home

端到端真实 BlackBerry 应用程序,第二部分

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.67/5 (3投票s)

2008年6月25日

CPOL

2分钟阅读

viewsIcon

32662

downloadIcon

202

端到端真实 BlackBerry 应用程序演练,第二部分。

引言

在本系列的第一篇文章中,我开始带领您完成端到端 BlackBerry 应用程序的创建,该应用程序将作为我的知识库示例 Web 应用程序的移动前端。

移动应用程序的要求非常简单

  1. 通过标题或标签搜索存储在知识库存储库中的文章集合。
  2. 查看文章。文章的可见属性包括:标题、正文、标签、作者姓名、发布日期。

我的构建模块看起来像这样

Building-Blocks1.gif

实现

之前,我已经完成了 Application 类和 Home Screen。

Home-Screen1.gif

现在我将继续完成其余的屏幕。

标签屏幕

“标签”屏幕显示数据库中现有标签的列表。 除了每个标签之外,还会显示该标签适用的文章数量。

Tags-Screen1.gif

搜索屏幕

该屏幕将允许我们的用户通过键入属于文章标题的一个或多个单词来发起文章搜索。

Search-Screen1.gif

searchArticles() 函数存在于“标签”屏幕和“搜索”屏幕中,到目前为止,它只是将“文章”屏幕推到堆栈的顶部。 稍后,我将添加代码,该代码将请求我的服务器端处理程序发出数据库查询并返回任何结果。

private void searchArticles() {
    String searchPhrase = searchPhraseField.getText().trim();
    if (null != searchPhrase && searchPhrase.length() > 0) {
        UiApplication.getUiApplication().pushScreen(articlesScreen);
        // TODO: Trigger the search function in the Articles Screen. 
    } else {
        Dialog.alert("You must enter a search phrase.");
    }
}

文章屏幕

“文章”屏幕显示满足“搜索”屏幕上输入的条件的文章列表。 它还可以显示最近查看的文章列表。 单击任何列出的文章会将“文章”屏幕带到堆栈顶部。

Articles-Screen1.gif

由于我仍然缺少网络例程,因此我创建了一些虚拟文章,以便测试“文章”屏幕的外观和感觉

ArticlesScreen() {
        
    this.setTitle("Articles");

    // Create a few dummy tags in order to test the screen;
    articles = new Article[15];
    Article article;
    for (int i = 0; i < 15; i++) {
        article = new Article();
        article.title = "Dummy article " + Integer.toString(i);
        article.author = "ramonj";
        article.contents = "This is a test article";
        article.tags = new String[] {"tag 1", "tag 2", "tag 3"};
        article.dateCreated = "01/01/2008";
        articles[i] = article;
    }
    
    articlesList = new ArticlesListField();
    articlesList.set(articles);
    this.add(articlesList);
}

下面显示了 Article 类。 请注意,我并没有太关注封装,因为此类仅在应用程序中的少数几个地方使用。

class Article {
    public String title;
    public String dateCreated;  
    public String author;
    public String[] tags;
    public String contents;
}

文章屏幕

“文章”屏幕显示“文章”屏幕上选择的文章的可查看属性。 这是用户阅读文章的地方。 这是我使用上面显示的 Article 类的另一个地方。

Article-Screen1.gif

选项屏幕

最后,“选项”屏幕允许用户更改应用程序设置。 就设置而言,到目前为止,我只能想到我们的应用程序将连接到的 URL,以便与其服务器对应部分进行通信,以及最近查看的文章的引用数量,以保持缓存在设备上。

Options-Screen1.gif

下一步

在本系列的下一篇文章中,我将添加网络代码以及保存和检索应用程序设置的代码。 在此之后,我将转移到服务器端,并处理将处理与设备通信的部件。

历史

© . All rights reserved.