如何使用屏幕对象访问屏幕上的文件(UiApplication.getUiApplication().getActiveScreen())

发布于 2024-11-03 08:31:23 字数 337 浏览 1 评论 0原文

我的问题是如何使用屏幕对象访问堆叠屏幕上的字段?

确切的问题如下:

我有一个屏幕,其中有一个文本字段(ClientName),当用户单击该字段时,应用程序将推送一个新屏幕,并允许用户使用 MyWebSerivces 在远程数据库中进行搜索。当用户从搜索结果中选择一个客户端时,我想使用用户在当前屏幕上选择的文本设置前一个屏幕上的文本字段。

我尝试过 PushScreen( new screen("text) ) 和如果我只想执行一次此操作,这可能是结果,但这不是我的选择,因为还有两个这样的字段将转到其他屏幕以从网络服务获取数据,并且如果我每次推送新的数据。然后在每次推屏操作后我只会得到一个包含所需文本的字段

My Query is How to access Fields on the stacked screen using Screen Object ?

The exact problem is as follows:

I have one screen which has one text field (ClientName) when user clicks on that field , application will then push a new screen and it will allow the user to search in remote database using MyWebSerivces. and when user selects the one client from the search result ,i want to set the text Field on the previous screen with the text that user has selected on the current screen..

i have tried the pushScreen( new screen("text) ) and that might be the result if i want to do this operation only once but this is not the option for me since there is two more such field which will go to other screen to fetch the data from webservices . and if i every time i push new screen then after every pushscreen operation i will only get one field set with the desired text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

摇划花蜜的午后 2024-11-10 08:31:23

这不是黑莓(或任何特定编程语言)相关的问题。这是一个应用程序架构和常识的问题。如果一个屏幕应更改另一个屏幕的 Field,则只需将 Field 的引用传递到将更改它的屏幕即可。

This not a blackberry (or any specific programming language) related question. This is a question of application architecture and common sense. If one screen should change a Field of another screen, then just pass a reference of the Field to the screen that will change it.

哭泣的笑容 2024-11-10 08:31:23

嗨,我曾经遇到过同样的问题,我是这样的:

Screen1

                  ------------------
  Client Name     |  text field     |
                  ------------------

当用户单击此文本字段或您按 Screen2 的任何按钮时
在屏幕 2 中,当用户选择特定值时,您将执行此操作。

1)在主类中使用一个静态变量,例如clientName。
2) 设置该变量的值。
3) 调用此代码时弹出活动屏幕

UiApplication.getUiApplication().getActiveScreen();

然后返回到 Screen1
现在在 screen1 中调用一个方法

    public void  onExposed()
    {
      //here u can set the text in textfield using the static variable 
      invalidate(); // for repainting
    }

hi i once had same problem and i did like this:

Screen1

                  ------------------
  Client Name     |  text field     |
                  ------------------

When user clicks on this text field or any button you push Screen2
In screen 2 when user selects a particular value then u do this.

1) take a static variable in main class say clientName.
2) set value of this variable.
3) pop active screen

UiApplication.getUiApplication().getActiveScreen();

when this code is called then u come back to Screen1
Now in screen1 a method is called

    public void  onExposed()
    {
      //here u can set the text in textfield using the static variable 
      invalidate(); // for repainting
    }
没企图 2024-11-10 08:31:23

我已经找到了我的问题的答案。解决方案就在我的问题中,但一开始我找不到它。
解决方案很简单
当我写作时,我想使用

UiApplication.getUiApplication().getActiveScreen() 

这几乎是正确的方式,并且我正在朝着正确的方向前进,但我缺少的是“我没有将屏幕(我刚刚从堆栈顶部检索)投射到其类型
我唯一应该做的就是“应该将屏幕投射为其类型。像这样,

UiApplication.getUiApplication().posScreen(this)
(MyScreen1) UiApplication.getUiApplication().getActiveScreen() 

现在我可以访问检索到的屏幕(MyScreen1)上的所有字段

,要记住的事情是

  1. 确保您仅将屏幕投射为其类型,否则bb 会给你找不到资源的错误

在堆栈上使用屏幕的好处

  1. 你可以使用堆栈中已经创建的屏幕,不需要创建新的屏幕,
  2. 如果你要创建新的屏幕,它将被堆叠在内存中,并且会消耗越来越多的内存,即使它没有用(如果没有用,请养成弹出屏幕的习惯,而不是将其留在堆栈上))
  3. 无需创建任何静态变量,因为您将能够立即从其他屏幕设置所有字段

i have found the answer to my question. the solution was there lying in my question but at first i was not able to find it.
solution was very simple
when i wrote i want to use

UiApplication.getUiApplication().getActiveScreen() 

that was almost the right way and i was proceeding in right direction but the thing that i was missing was " I was not casting the screen (that i have just retrieved form the stack top ) to its type
only thing i should have done is "should have casted screen to its type.like this

UiApplication.getUiApplication().posScreen(this)
(MyScreen1) UiApplication.getUiApplication().getActiveScreen() 

now i am able to access all the fields on the retrieved screen (MyScreen1)

things to keep in mind

  1. make sure u cast the screen to its type only otherwise bb will give u resource not found error

Benifits of using screen on Stack

  1. u can use already created screen from the stack no need to create new one
  2. if u will create new screen it will be stacked in memory and will consume more and more memory even if its of no use ( make habit to pop the screen if it is of no use instead of leaving it on stack))
  3. no need to create any static variable since u will be able to set all the field right away from other screen
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文