使用代码访问通过 LWUIT 资源编辑器创建的表单
我正在尝试使用 LWUIT 资源编辑器开发一个测验应用程序,但遇到了很大的困难。
我创建了两个 Forms
'GUI1' 和 'GUI2' 。
GUI1 显示以下内容:
- 一个问题(以
TextField
的形式) - 属于同一组的 5 个
RadioButtons
- 一个显示“OK”的
Button
GUI2 显示以下内容:
- 一个
TextField
- 一个返回 GUI1 的
Button
现在问题是:
最初显示 GUI1。当用户选择 RadioButton
时,我想知道选择了哪个 RadioButton
。如果该 RadioButton
确实是正确答案,那么当用户单击 GUI1 上的“确定”Button
时,我希望在 中显示文本“正确” GUI2 上的 >TextField
,然后显示 GUI2。
如果用户选择了错误的答案,那么我希望在 GUI2 上的 TextField
中显示文本“错误”,然后显示 GUI2。
如何使用资源编辑器来完成此操作?我很狡猾。请帮忙。 当我当前使用 GUI1 时,我希望引用 GUI2 上的 TextField
。如何使用资源编辑器来完成此操作?为所有这些编写手动代码将非常耗时。
I am trying to develop a quiz application using LWUIT resource editor and am having great difficulty.
I have created two Forms
'GUI1' and 'GUI2' .
GUI1 displays the following:
- A question(in the form of a
TextField
) - 5
RadioButtons
belonging to the same group - A
Button
which says 'OK'
GUI2 displays the following:
- A
TextField
- A
Button
to go back to GUI1
Now the problem is:
Initially GUI1 is displayed. When the user chooses a RadioButton
, I wish to know which RadioButton
was selected. If that RadioButton
was indeed the correct answer, then when the user clicks on the 'OK' Button
on GUI1, I wish to display the text 'correct' in the TextField
on GUI2 and then display the GUI2.
If the user chose the wrong answer, then I wish to display the text "Wrong" in the TextField
on GUI2 and then display the GUI2.
How can this be done with resource editor? I am very foxed. Please help.
I wish to refer to the TextField
on GUI2 when I am currently on GUI1. How can this be done with resource editor? Writing a manual code for all this would be very time consuming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我会尽力解释。
当您设计第一个
Form
GUI1 时,五个RadioButton
必须位于同一组中。我不知道如何在资源编辑器中执行此操作(我认为RadioButton
中有一个名为 ButtonGroup 的字段,但我不记得了)。我要做的就是通过 GUI1 的 before 方法中的代码获取五个RadioButton
并将它们添加到ButtonGroup
元素中。通过
ButtonGroup
,您可以使用ButtonGroup.setSelectedIndex()
知道选择了哪个元素。当您按下按钮
时,获取该值并根据具体情况采取适当的行动。如果您有什么不明白的地方请告诉我,我会尽力帮助您。
并不是一件难事。一定有办法用资源编辑器来做到这一点,但目前我不知道如何做。
Ok I will try to explain the best I can.
When you design the first
Form
GUI1 the fiveRadioButtons
must be in the same group. I don't know how to do that in the resource editor (I think there is a field called ButtonGroup in theRadioButton
, but I can't remeber). What I would do is take the fiveRadioButton
by code in the before method of GUI1 and add them to aButtonGroup
element.With
ButtonGroup
you can know which element is selected usingButtonGroup.setSelectedIndex()
. When you press theButton
take this value and act as appropriate to the situation.If you don't understand anything please tell me and I will try to help you.
Is not a hard thing to do. There must be a way to do it with the Resoruce editor but at the moment I don´t know how.
正如 Shai 提到的,最好的办法是使用侦听器在单击按钮时设置按钮的“状态”,当您移动到下一个表单时,您只需检索上一个文本字段的状态。
手动代码实际上对您来说可能更快,在资源编辑器中完成大部分 UI 操作并转换为手动编写的表单。这样您就可以完全控制您的对象,并在需要时返回到 GUI 构建器表单。
As Shai mentioned, the best thing to do is to use listeners to set the "state" of the buttons on clicking them and when you move to the next form you just retrieve the state of the previous text field.
Manual code may actually be faster for you, do most of the UI in the resource editor and transfer to a form that is written manually. That way you have full control over your objects and transfer back into the GUI builder form when needed.