在 Android 的视图中打开一个包含文本输入的对话框
我有一个带有基于 SurfaceHolder 的视图的应用程序(类似于 Lunar Lander 教程)。 整个 GUI 绘制在画布上,我希望能够使用自定义布局对话框在给定时刻提示用户文本输入,然后使用标准程序处理并渲染到画布上。
然而,我的问题是,最佳实践似乎是从活动中打开对话框。 这也没有问题,因为我认为我可以创建一个处理程序,然后将其传递给视图,视图又可以使用它将消息从视图中的 GUI 线程传递到活动,进而可以获取输入, 问题是,在我调用包含整个应用程序的
setContentView(R.layout.main)
后,我想调用 MyAppView mMyAppView = (MyAppView) findViewById (R.id.app_view_id)
。
此调用返回null
。
这里什么被认为是最佳实践?我找不到任何好的例子,而且 API 正在出现,好吧,不多。
如果有任何帮助,我将不胜感激。
I have an app with a View based on the SurfaceHolder (similar to the Lunar Lander tutorial).
The whole GUI is drawn on a canvas, and I want to be able to prompt for user text input at a given moment using a custom layout Dialog, that is then taken care of and rendered to the canvas using standard procedure.
My problem, however, is that it seems that best practice is to open Dialogs from the Activity.
This is no problem either, since i thought i might create a Handler and then pass it to the View that could in turn use it to pass Messages from the GUI thread in the View on to the Activity, that in turn could fetch the input, and send a reply back, etc.
Problem is, after I call setContentView(R.layout.main)
, which contains the whole app, i want to call MyAppView mMyAppView = (MyAppView) findViewById(R.id.app_view_id)
.
This call returns null
.
What is considered to be best practice here? I can't find any good examples and the API is turning up, well, not much.
I would appreciate any help here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个对话框主题活动以显示当前活动。
启动方式:
然后捕获
onActivityResult
上的响应Manifest 定义为:
Create a dialog themed activity to display over your current activity.
Launch by:
then catch the response on
onActivityResult
Manifest is defined as:
我也想为自己回答这个问题。这里已经给出了一个很好的答案。 Android 开发者页面作为更改对话框 样本。
我还没有完全阅读它,但是如果您搜索标签
DIALOG_TEXT_ENTRY
这似乎就是您(和我)所需要的。
我将首先研究这个例子。
I am also looking to answer this question for myself. The answer already here is a good one. The android developer page as alter dialog samples.
I haven't read it completely yet, but if you search for the tag
DIALOG_TEXT_ENTRY
this would seem to be what you (and I) need.
I'm going to investigate that example first.