【问题标题】:Using tabs and MapActivitys (Android)使用选项卡和 MapActivity (Android)
【发布时间】:2010-10-26 17:34:55
【问题描述】:

如何使用标签在活动之间切换?例如,我有一些标签,其中一个包括谷歌地图,我希望每个标签都有自己的活动和自己的 .xml 文件。我该怎么做?

【问题讨论】:

    标签: java android google-maps


    【解决方案1】:

    《APress Begining android 2》一书中有一个教程可以做到这一点。

    Download the source

    使用源代码“Fancy\Tab”中的文件夹从 Eclipse 中的现有源创建一个 android 项目

    在您运行标签内容后,只需将加载到标签中的活动替换为您想要的内容。即一个 MapActivity。

    【讨论】:

    • 你的意思是我应该在 main.xml 中写 spec.setContent(R.layout.[name]) 而不是 spec.setContent(R.id.tab1) 和 FrameLayout 应该是空的?我试过了,但有异常
    【解决方案2】:

    iv也尝试过这种方式,但同样的异常

            TabHost tabs=(TabHost)findViewById(R.id.tabhost);          
            Intent intent = new Intent().setClass(this, home_scr.class);
            TabHost.TabSpec spec = tabs.newTabSpec("tabHome").setIndicator("H").setContent(intent);
            tabs.addTab(spec);
    

    【讨论】:

      【解决方案3】:

      我已经解决了这个问题。除了

          TabHost tabs=(TabHost)findViewById(R.id.tabhost);          
          Intent intent = new Intent().setClass(this, home_scr.class);
          TabHost.TabSpec spec = tabs.newTabSpec("tabHome").setIndicator("H").setContent(intent);
          tabs.addTab(spec);
      

      带有TabHost描述的xml文件中“android:id”的值必须是“@android:id/tabhost”,FrameLayout也必须有“android:id="@android:id/tabcontent”,但不能有其他名称.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多