就这么迷失了...ViewSwitcher?创建一个 Activity 然后添加到 ViewSwitcher 中?
我是 Android 新手,发现它很残酷(似乎有无数的细节和依赖项需要记住)。
无论如何,我让 TextSwitcher1 示例应用程序正常工作,它使用 ViewSwitcher。我假设 ViewSwitcher 是可行的方法,需要显示地图或表格,用户可以选择并来回切换。
所以我在另一个应用程序中创建了我的 MapActivity,似乎有效。接下来集成到主应用程序中。所以,打电话 视图 v = findViewById(R.layout.mapview); 进而 mSwitcher.addView(v); 除了“v”为空之外。为什么?我要创建活动吗?但我还不想展示它。是否有“创建活动但隐藏它直到需要时”之类的调用?还是我找错了树?
感谢您的任何见解。
I'm new to Android and find it brutal (there seems to be an near infinite number of details and dependencies to remember).
Anywho, I got the TextSwitcher1 example app working, which uses ViewSwitcher. I'm assuming ViewSwitcher is the way to go, need to either display a map or a table, user can pick, and switch back and forth.
So I created my MapActivity in another application, seems to work. Next integrate into main app. So, call
View v = findViewById(R.layout.mapview);
and then
mSwitcher.addView(v);
except "v" is null. Why? Do I create the activity? But I don't want to show it yet. Is there such a call as "create activity but hide it until needed"? Or am I barking up the wrong tree?
Thanks for any insight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
findViewById
函数根据您在 Activity 中加载的任何视图的 ID 资源 (R.id.something
) 返回一个View
(使用setContentView(R.layout.main)
)。在示例代码中,您使用布局资源 (R.layout.mapview
)。您应该扩充 XML 文件,该文件将返回一个View
,您可以使用它添加到ViewSwitcher
。示例代码:
但是,您应该能够定义 XML 文件中的所有内容,而不必手动将页面添加到
ViewSwitcher
中。以下是有关如何执行此操作的一些示例代码: http://inphamousdevelopment.wordpress.com/2010/10/11/using-a-viewswitcher-in-your-android-xml-layouts/The
findViewById
function returns aView
based on an ID resource (R.id.something
) for whatever view you have loaded in your activity (usingsetContentView(R.layout.main)
). In your sample code, you're using a layout resource (R.layout.mapview
). You should inflate the XML file, which will return aView
that you can use to add to theViewSwitcher
.Example Code:
However, you should be able to define everything in your XML file and not have to manually add the pages to your
ViewSwitcher
. Here's some example code on how to do that: http://inphamousdevelopment.wordpress.com/2010/10/11/using-a-viewswitcher-in-your-android-xml-layouts/